C# 使用HttpWebRequest Post
2014-02-19 15:53
309 查看
1.代码
有因为POST的数据格式有xml,json,form等格式,为了让服务器后台明确数据的格式,最好指明ContentType,否则可能出现服务器接受不到参数
3.附:
form表单格式:application/x-www-form-urlencoded
json格式:json/application
xml格式:text/xml
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; byte[] data=Encoding.ASCII.GetBytes(String.Format("id={0}&balance={1}",id,balance)); request.ContentLength = data.Length; request.GetRequestStream().Write(data, 0, data.Length); request.GetRequestStream().Flush(); request.GetRequestStream().Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr =new StreamReader( response.GetResponseStream() );2.注意
有因为POST的数据格式有xml,json,form等格式,为了让服务器后台明确数据的格式,最好指明ContentType,否则可能出现服务器接受不到参数
3.附:
form表单格式:application/x-www-form-urlencoded
json格式:json/application
xml格式:text/xml
相关文章推荐
- C# 使用HttpWebRequest用Post提交MultiPart数据
- C#中使用HttpWebRequest用Post提交MultiPart数据
- C# 使用HttpWebRequest用Post提交MultiPart数据
- 【转】asp.net(c#)使用HttpWebRequest附加携带请求参数以post方式模拟上传大文件(以图片为例)到Web服务器端
- C#使用HttpWebRequest POST或GET信息
- C#中使用HttpWebRequest用Post提交MultiPart数据
- HttpWebRequest的使用之Get和Post的差别(C#)
- C#中使用HttpWebRequest用Post提交MultiPart数据
- 用C#使用HttpWebRequest Post数据时如何保持Session
- C# 后台使用HttpWebRequest发送POST请求帮助类
- C# 使用HttpWebRequest Post提交数据,携带Cookie和相关参数示例
- C#中使用HttpWebRequest用Post提交MultiPart数据
- C#中使用HttpWebRequest用Post提交MultiPart数据
- C# 使用HttpWebRequest Post提交数据,携带Cookie和相关参数示例
- C#使用HttpWebRequest 进行get 和post提交
- asp.net(c#)使用HttpWebRequest附加携带请求参数以post方式模拟上传大文件(以图片为例)到Web服务器端
- 使用HttpWebRequest post数据时要注意UrlEncode
- 使用HttpWebRequest post数据时要注意UrlEncode
- 使用 HttpWebRequest 发送模拟 POST 请求
- 使用HttpWebRequest发送自定义POST请求