资源简介
.net 后台Post,get方式调用webapi,包括上传文件
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.IO;
namespace IceMakeCommon
{
public class HttpHelper
{
public static string GetHttpContentType(string ext)
{
string cType = “image/jpeg“;
switch (ext.ToLower())
{
case “.jpg“:
case “.jpeg“:
cType = “image/jpeg“;
break;
case “.png“:
cType = “image/png“;
break;
case “.bmp“:
cType = “image/bmp“;
break;
case “.gif“:
cType = “image/gif“;
break;
default:
cType = “application/octet-stream“;
break;
}
return cType;
}
///
/// 模拟http post请求
///
///
///
///
public static string CreateHttpPostResponse(string url IDictionary parameters)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException(“url“);
}
HttpWebRequest request = null;
//如果是发送HTTPS请求
if (url.StartsWith(“https“ StringComparison.OrdinalIgnoreCase))
{
//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
//request = WebRequest.Create(url) as HttpWebRequest;
//request.ProtocolVersion = HttpVersion.Version10;
}
else
{
request = WebRequest.Create(url) as HttpWebRequest;
}
request.Method = “POST“;
request.Headers.Add(“X_REG_CODE“ “288a633ccc1“);
request.Headers.Add(“X_MACHINE_ID“ “a306b7c51254cfc5e22c7ac0702cdf87“);
request.Headers.Add(“X_REG_SECRET“ “de308301cf381bd4a37a184854035475d4c64946“);
request.Headers.Add(“X_STORE“ “0001“);
request.Headers.Add(“X_BAY“ “0001-01“);
request.Headers.Add(“X-Requested-With“ “xmlHttpRequest“);
request.ContentType = “application/x-www-form-urlencoded“;
request.Headers.Add(“Accept-Language“ “zh-CN“);
request.Headers.Add(“Accept-Encoding“ “gzip deflate“);
request.Accept = “*/*“;
request.CookieContainer = new CookieContainer();
//如果需要POST数据
if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10554 2015-03-06 16:48 .net 后台Post,get方式调用webapi\HttpHelper.cs
目录 0 2015-03-26 17:28 .net 后台Post,get方式调用webapi
----------- --------- ---------- ----- ----
10554 2
- 上一篇:Win32API编程入门
- 下一篇:asdoc.zip
相关资源
- 网络请求----HttpURLConnection的get,post和
- VC Socket GET_POST发送HTTP请求
- delphi 7 idhttp post 的8种使用方法(含源
- WebAPIFileDemo
- 中国邮政条形码 (China Postal Code)
- 易语言 通过POST向网页上传文件 模块
- VC HTTP请求 GET POST
- WebApi系列-通过HttpClient来调用WebApi接口
- 奶牛快传,一个不限速的临时网盘的
- 完整的roundcube邮件系统搭建过程
- CAMPOST V19
- 3分钟安装配置Postfix邮件服务器
- vs连接postgre
- 异步HTTP请求及异步HTTP单元基于autoU
- C代码版本的HTTP POST上传文件/JSON
- 一个delphi封装的WinHttp
- 易语言POST上传文件.rar
- labview HTTP POST 通信程序 Demo.vi
- 百度POST实时推送V3.0
- postman教程.txt
- K3 CLOUD WEBAPI接口说明书
- 自己分装的一个winhttp类
- Delphi通过https接口post数据
- Posterior Regularization for Structured Latent
- 调用webservice,通过post传参读取返回的
- Xamarin移动开发Get、Post服务请求源码
- pb9 通过http、https协议post
- Unity Post Processing Profiles v2.1
- postmark+教程
- wininetForNet源代码
评论
共有 条评论