WebClient 通过get和post请求api
2017-09-19 10:14
435 查看
//get 请求
string url = string.Format("http://localhost:28450/api/values?str1=a&str2=b");
WebClient wc = new WebClient();
Encoding enc = Encoding.GetEncoding("UTF-8");
Byte[] pageData = wc.DownloadData(url);
string re = enc.GetString(pageData);
//post 请求
string postData = "value=a";
byte[] bytes = Encoding.UTF8.GetBytes(postData);
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("ContentLength", postData.Length.ToString());
Encoding enc = Encoding.GetEncoding("UTF-8");
byte[] responseData = client.UploadData("http://localhost:28450/api/values", "POST", bytes);
string re = enc.GetString(responseData);
string url = string.Format("http://localhost:28450/api/values?str1=a&str2=b");
WebClient wc = new WebClient();
Encoding enc = Encoding.GetEncoding("UTF-8");
Byte[] pageData = wc.DownloadData(url);
string re = enc.GetString(pageData);
//post 请求
string postData = "value=a";
byte[] bytes = Encoding.UTF8.GetBytes(postData);
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("ContentLength", postData.Length.ToString());
Encoding enc = Encoding.GetEncoding("UTF-8");
byte[] responseData = client.UploadData("http://localhost:28450/api/values", "POST", bytes);
string re = enc.GetString(responseData);
相关文章推荐
- WebClient 通过get和post请求api
- WebClient 通过get和post请求api
- 跨域调用接口——WebClient通过get和post请求api
- 跨域调用接口——WebClient通过get和post请求api
- VB.NET通过URL POST请求和GET请求
- PHP:CURL分别以GET、POST方式请求HTTPS协议接口api
- javaservlet处理四种常用api请求get,put,post,delete
- android开发学习笔记(一)分别通过GET和POST请求从服务器端获取数据
- Java 通过HttpClient 带证书方式请求Https协议网站 (Post方式带xml文档,Get以及Delete方式)
- iOS iPhone通过get和post方式请求asp.net webservice
- iphone之通过get和post方式请求asp.net webservice
- 通过 NSURLConnection 发送 HTTP GET /HTTP POST /HTTP DELETE /HTTP PUT 请求
- 在servlet中GET请求可以通过HttpServletRequest的getRequestURL方法和getQueryString()得到完整的请求路径和请求所有参数列表,POST的需要getPa
- 梦网云通讯获取状态报告API接口get_rpt说明POST请求示例
- C# winform端 通过HttpWebRequest进行post和get请求,数据格式为json,后台java端接收,其中有关传输特殊字符(\t,\r,',\n,n)等处理
- 通过浏览器地址进行 post get 请求
- C#中GET、POST请求API
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- 通过get或post请求URL获取返回数据
- 通过AsyncTask实现网络请求的方式,get和post