var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
//构造要传递的json对象 (Jobject的实例)
var jObject=new JObject();
jObject["para1"]="data1";
...
var postData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jObject));
request.ContentLength = postData.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(postData, 0, postData.Length);//将json数据发送
}
var response = (HttpWebResponse)request.GetResponse();
string result;
using (var reader = new StreamReader(response.GetResponseStream()))
{
//读取请求返回值
result = reader.ReadToEnd();
}
C# http request response
最新推荐文章于 2024-05-18 16:36:40 发布