c# from 采用WebClient调用web api 源码
///url,web api 地址
public static string GetInfo(string url)
{
string URI = url;
//实例化
WebClient client = new WebClient();
// client.UseDefaultCredentials = true;
return Encoding.UTF8.GetString(client.DownloadData(URI));
}
/// <summary>
/// Post API
/// </summary>
/// <param name="url"></param>
/// <param name="myParameters">LPN=鄂A88887&UserNo=GJH</param>
/// <returns></returns>
public static string PostInfo(string url,string myParameters)
{
//string LPN = "鄂A88887";
//string UserNo = "GJH";
//string URI = url;
//string myParameters = "LPN=鄂A88887&UserNo=GJH";
//实例化
WebClient client = new WebClient();
// client.UseDefaultCredentials = true;
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
client.Encoding = Encoding.UTF8;
string a = client.UploadString(url, myParameters);
return a;
}