Http Post Json参数及Json接收
2021-07-12 02:05
标签:lis read request ons write using list var toe private string HttpRequest(Dictionary using (WebResponse listResponse = request.GetResponse()) Http Post Json参数及Json接收 标签:lis read request ons write using list var toe 原文地址:https://www.cnblogs.com/chixiner/p/14981559.html
{
string json = JSONhelper.ObjToJson(dic);
WebRequest request = WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json";
using (Stream requestStream = request.GetRequestStream())
{
var bytes = Encoding.UTF8.GetBytes(json);
requestStream.Write(bytes, 0, bytes.Length);
}
using (Stream responseStream = listResponse.GetResponseStream())
using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
{
string result = string.Empty;
if (readStream != null) result = readStream.ReadToEnd();
return result;
}
}
上一篇:HTML基本结构