http post 请求
来源:互联网 发布:java解析xml文件实例 编辑:程序博客网 时间:2024/06/15 05:25
public static string PostWebRequest(string key)
{
string postUrl = System.Configuration.ConfigurationManager.AppSettings["ServiceUrl"] + "/DataService.ashx?sid=" + HttpContext.Current.Session.SessionID;
string paramData="";
Encoding dataEncode = Encoding.UTF8;
string ret = string.Empty;
try
{
StringBuilder sb = new StringBuilder();
sb.Append("&key=" + key);
paramData = sb.ToString();
byte[] byteArray = dataEncode.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message);
}
return ret;
}
{
string postUrl = System.Configuration.ConfigurationManager.AppSettings["ServiceUrl"] + "/DataService.ashx?sid=" + HttpContext.Current.Session.SessionID;
string paramData="";
Encoding dataEncode = Encoding.UTF8;
string ret = string.Empty;
try
{
StringBuilder sb = new StringBuilder();
sb.Append("&key=" + key);
paramData = sb.ToString();
byte[] byteArray = dataEncode.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message);
}
return ret;
}
0 0
- android http post请求
- http的post请求
- C# http post请求
- HTTP 模拟post请求
- http post get 请求
- http请求post
- ios HTTP post请求
- HTTP GET/POST 请求
- http post get请求
- http post 客户端请求
- HTTP POST 网络请求
- http 原生post 请求
- http post请求
- http请求 get post
- http post请求
- http post 请求
- http post get请求
- http post请求
- 将数字1-9分为三组,使每组构成一个3位数的平方数.
- 对于大学4年的反思
- 【设计模式总结篇】
- ORACLE(SEQUENCE)序列总结
- Android开发之旅:进程与线程
- http post 请求
- 深度学习资料链接整理
- 鸡汤一碗 与君共勉
- web图表---Highcharts使用指南
- Spring中的ContextLoaderListener作用
- cocos2d-x 以主角为中心移动地图(学习笔记)
- 基于Linux kernel 3.14版本移植安卓系统后触摸屏无法使用的问题
- 修改SELinux状态
- 防表单重复提交