GET获取数据
WebClient client = new WebClient();
//设置编码格式
client.Encoding = System.Text.Encoding.UTF8;
//获取数据
var result = client.DownloadString(url);
POST提交数据
WebClient client = new WebClient();
//添加请求头
client.Headers.Add("key", "value");
//创建请求体
NameValueCollection nvc = new NameValueCollection();
nvc.Add("key1", "value1");
nvc.Add("key2","value2");
string url = "http://wf.h5120.com:5280/admin/users/";
//提交数据
var btys = client.UploadValues(url, nvc);
//解析提交返回结果
string str = System.Text.Encoding.UTF8.GetString(btys);
网友评论