使用http调用接口的办法
//下载using System.Net.Http;
项目中的具体使用的方法
get
post
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string url = "http://api.oa.com/api/Test/Post";
var json = "{ \"Name\": \"Test\" }";
var httpContent = new StringContent(json, Encoding.UTF8);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = client.PostAsJsonAsync(url, httpContent).Result;
if (!response.IsSuccessStatusCode)
{
Response.Write(string.Format("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase));
}
原文:http://www.cnblogs.com/hkyyqqq/p/7486087.html