跨域调用接口——WebClient通过get和post请求api
来源:互联网 发布:淘宝卖水果需要什么 编辑:程序博客网 时间:2024/05/23 14:52
//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);DownloadString(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);
//调用接口Demo
string url = "http://localhost:62691/SessionState/TransmitSession";//获取会话同步接口 string sendAccount = "fff2221111"; string acceptedAccount = "qckf_wx"; string msgType = "text"; string content = "测试下22"; string nickname = "山本松井"; //调用接口进行同步 string timeStamp = GetTimeStamp();//获取时间戳 string sign = DESEncrypt.Encrypt(timeStamp, "dxqmp52c0esxymru"); string postData = "sendAccount=" + sendAccount + "&acceptedAccount=" + acceptedAccount + "&msgType=" + msgType + "&content=" + content + "×tamp=" + timeStamp + "&sign=" + sign + "&nickname=" + nickname + ""; 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(url, "POST", bytes); string re = enc.GetString(responseData);
来源:http://blog.csdn.net/zhaoqi5705/article/details/14920667
- 跨域调用接口——WebClient通过get和post请求api
- WebClient 通过get和post请求api
- WebClient 通过get和post请求api
- WebClient的get和post动态请求
- WebClient Post 和 Get
- java HttpUrlConnection get和post 模拟请求 调用接口
- post和get请求调用Http接口并拿到数据
- java HttpClient get post请求 调用接口
- CURL 请求外部接口 GET 和 POST
- 【接口测试】:HttpClient Post 和 Get 请求
- Http的GET请求与POST请求调用接口
- Android HTTP实例 使用GET方法和POST方法发送请求(通过Apache接口实现)
- API调用:GET、POST
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求,调用http接口、方法
- JAVA发送http get/post请求、调用http接口、方法
- 控制反转(IOC)
- Qt之按钮部件
- Url重写——伪静态实现
- 搜索-D
- 马云说:未来30年是“用好互联网技术”的国家的天下_是“用好互联网技术”的年轻人的天下。
- 跨域调用接口——WebClient通过get和post请求api
- 使用C#把发表的时间改为几年前,几个月,几天前,几小时前,几分钟前,或几秒前
- 利用Jquery实现http长连接(LongPoll)
- SignalR——聊天室的实现
- Eclipse快捷键 10个最有用的快捷键
- Chosen:Select 选择框的华丽变身
- js学习笔记--BOM(Browser对象)
- JSONP跨域实现
- VS头部自动注释