C#通过发送 http 请求调用接口之Post
来源:互联网 发布:海报模板网站 知乎 编辑:程序博客网 时间:2024/04/28 16:58
1.实现车辆审核回调接口(包含车辆基本信息数据)
(1)描述
本接口提供运政车辆基本信息回传服务,调用方式请使用 post 方式提交。
(2)接口调用示例:
待加密格式
type=xxx&user=xxx&pwd=x&vclN=xxx&pltClr=xx&vclClr=xx&area=xx&hsHld=xx...
(3)请求地址格式
http://xxx/vinfos?p=加密后数据
(4)实现:
void btnTransferVehicleAudit_Click(object sender, EventArgs e) { DateTime dt = Convert.ToDateTime("2014-01-09 16:47:24"); long dtNow = ConvertDateTimeToInt(DateTime.Now); long dtSpanTime = ConvertDateTimeToInt(dt); StringBuilder sb = new StringBuilder(); sb.Append("type=xxx&user=xxx&pwd=0&vclN=xxx&pltClr=2&vclClr=2&area=xx&hsHld=xx&vclCt=xx"); sb.Append("&vclBsTp=xx&vclTps=xx&vclUsTp=xx&vclLng=xx&vclWdt=xx&vclHgt=xx&boxLng=xx&boxWdt=xx&boxHgt=xx"); sb.Append("&boxCnt=xx&lftHgt=xx&twoTstStrd=xx®LicN=xx&drvLicBgDt=xx&drvLicBrd=xx&vin=xx&vclOrg=xx&rdTrans=xx&opStt=xx"); .... string strEn = Encrypt.Security.EnCode(sb.ToString());//加密 string url = "http://114.242.194.231:8084/BasisInfoInterface/vinfos"; Stream outstream = null; Stream instream = null; StreamReader sr = null; HttpWebResponse response = null; HttpWebRequest request = null; Encoding encoding = System.Text.Encoding.GetEncoding("gb2312"); byte[] data = encoding.GetBytes("p=" + strEn); // 准备请求... try { // 设置参数 request = WebRequest.Create(url) as HttpWebRequest; CookieContainer cookieContainer = new CookieContainer(); request.CookieContainer = cookieContainer; request.AllowAutoRedirect = true; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; outstream = request.GetRequestStream(); outstream.Write(data, 0, data.Length); outstream.Close(); //发送请求并获取相应回应数据 response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求 instream = response.GetResponseStream(); sr = new StreamReader(instream, encoding); //返回结果网页(html)代码 string content = sr.ReadToEnd(); //处理返回值 string quReply = Encrypt.Security.DeCode(content); //解密 string jsona = @quReply; JavaScriptSerializer jscvt = new JavaScriptSerializer(); //将jsona字符串转变成指定类型对象 TransferResult objQuery = jscvt.Deserialize<TransferResult>(jsona); switch (objQuery.code) { case "10000": ShowErrorMessage("添加成功2"); break; case "10001": ShowErrorMessage("添加失败"); return; case "20001": ShowErrorMessage("用户名或者密码错误"); return; case "30001": ShowErrorMessage("参数为空"); return; case "90001": ShowErrorMessage("其它异常"); return; case "90002": ShowErrorMessage("系统异常"); return; } } catch (Exception ex) { string err = ex.Message; } }
0 0
- C#通过发送 http 请求调用接口之Post
- C#通过发送 http 请求调用接口之Get
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求、调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- C# 通过接口 post 请求
- c#发送http请求get post
- C#发送Post方式的Http请求
- C# Http 发送Post请求实例
- C#发送HTTP POST请求和响应POST请求
- Android HTTP实例 使用GET方法和POST方法发送请求(通过Apache接口实现)
- C#通过Http发送Soap请求
- C#通过Http发送Soap请求
- http 发送post请求
- php中交互部分的总结
- Unity3D——汽车游戏自学1
- c语言基础问题汇总
- 一个c++类,尽可能标准
- 互质的数取模一定有循环节?
- C#通过发送 http 请求调用接口之Post
- struct vsf_sysutil_statbuf
- Android Camera学习总结:如何在android中使用摄像头获取照片
- 欢迎您在新浪博客安家
- 截止是11月18号
- 路由器及其工作原理
- MAC ACL、RACL和VACL
- 以太网交换机和路由器的工作…
- 搜索引擎常用技巧——英文资料篇