引用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");
wReq.Method = "Post";
wReq.ContentType = "application/json";
byte[] data = Encoding.Default.GetBytes("{\"ModifyDate\": \"sample string 1\",\"TimeStamp\": 2,\"Sign\": \"sample string 3\"}");
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即返回值
}
原文:http://www.cnblogs.com/niuniu0108/p/7655463.html