标签:
终于搞得差不多明白了,总结如下(省略了try catch),参考自这里
1.get:
一坨url带着"编码好"(urlencode需要自己处理)的参数(可以看到)一块发送给服务器:eg:
public async Task<string> GetAsync(string uri) { var httpClient = new HttpClient {Timeout = new TimeSpan(0, 0, 0, 17)}; var content = await httpClient.GetStringAsync(uri); return content; }
2.post:
一坨url+看不到的参数一块转化为数据流(urlencode可以提前处理)发送给服务器。
eg:
public async Task<string> PostAsync(string url, Dictionary<string, string> para) { var httpClient = new HttpClient {Timeout = new TimeSpan(0, 0, 0, 17)}; var contenta = new FormUrlEncodedContent(para); var response = await httpClient.PostAsync(url, contenta); string content = await response.Content.ReadAsStringAsync(); return content; }
标签:
原文地址:http://www.cnblogs.com/defoliate/p/4323455.html