C# 调用WEBAPI
2021-05-06 18:29
标签:ons tle requests webapi local encoding get orm host 引用DLL System.Net.Http System.Net.Http.Formatting 引用命名空间 using System.Net; using System.IO; HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create("http://localhost:8087/api/Test/TestAPI"); byte[] data = Encoding.Default.GetBytes("{\"ModifyDate\": \"sample string 1\",\"TimeStamp\": 2,\"Sign\": \"sample string 3\"}"); C# 调用WEBAPI 标签:ons tle requests webapi local encoding get orm host 原文地址:http://www.cnblogs.com/niuniu0108/p/7655463.html
wReq.Method = "Post";
wReq.ContentType = "application/json";
wReq.ContentLength = data.Length;
Stream reqStream = wReq.GetRequestStream();
reqStream.Write(data, 0, data.Length);
reqStream.Close();
using (StreamReader sr = new StreamReader(wReq.GetResponse().GetResponseStream()))
{
string result = sr.ReadToEnd();
//result即返回值
}