WebClient:
get:
System.Net.WebClient wCient = new System.Net.WebClient();
wCient.Headers.Add("Content-Type", "application/Json");
try
{
string url;
Byte[] responseByte = wCient.DownloadData(url);
result = Encoding.UTF8.GetString(responseByte);//返回接受的数据
}
post:
System.Net.WebClient wCient = new System.Net.WebClient();
wCient.Headers.Add("Content-Type", "application/Json");
try
{
string url;
byte[] dataByte = Encoding.UTF8.GetBytes(string);
byte[] responseByte = wCient.UploadData(url, "POST", dataByte);
result = Encoding.UTF8.GetString(responseByte);//返回接受的数据
}
HttpClient:
get: