所谓的潇洒

导航

Http Post Json参数及Json接收

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;
}
}

posted on 2021-07-07 15:05  所谓的潇洒  阅读(653)  评论(0编辑  收藏  举报