码迷,mamicode.com
首页 > Web开发 > 详细

Http Post Json参数及Json接收

时间:2021-07-07 17:56:22      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:lis   read   request   ons   write   using   list   var   toe   

private string HttpRequest(Dictionary<string, object> dic, string url)
{
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 (WebResponse listResponse = request.GetResponse())
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;
}
}

Http Post Json参数及Json接收

标签:lis   read   request   ons   write   using   list   var   toe   

原文地址:https://www.cnblogs.com/chixiner/p/14981559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有
迷上了代码!