HttpClient
2015-11-02 12:40
344 查看
public void UserLogin() { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", default_Token); List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>(); paramList.Add(new KeyValuePair<string, string>("grant_type", "password")); paramList.Add(new KeyValuePair<string, string>("activationCode", "CloudPeak")); paramList.Add(new KeyValuePair<string, string>("deviceId", "CloudPeak")); var response = client.PostAsync(serverUrl+"/OAuth/Token", new FormUrlEncodedContent(paramList)).Result; var str = response.Content.ReadAsStringAsync().Result; var aa = JObject.Parse(str).ToObject<Dictionary<string, string>>(); string tokenstr = aa["access_token"]; user_Token = "Bearer " + tokenstr; isUserLogin = true; //MessageBox.Show(tokenstr); } }
public void GetKaipiaoList(string startTime,string endTime,string searchKey) { using (HttpClient client = new HttpClient()) { string urlstr = serverUrl + "/api/services/app/invoiceRecord/GetInvoiceRecordPagedList"; client.DefaultRequestHeaders.Add("Authorization", user_Token); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("MaxResultCount", "100"); dic.Add("SkipCount", 0); dic.Add("Sorting", ""); dic.Add("BeginDateTime", "2015-10-01 11:11:11"); dic.Add("EndDateTime", "2016-10-01 11:11:11"); dic.Add("SearchValue", ""); HttpContent content = new StringContent(JsonConvert.SerializeObject(dic)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = client.PostAsync(urlstr, content).Result; var str = response.Content.ReadAsStringAsync().Result; MessageBox.Show(str); //var aa = JObject.Parse(str).ToObject<Dictionary<string, string>>(); //string tokenstr = aa["access_token"]; //user_Token = "Bearer " + tokenstr; //isUserLogin = true; //MessageBox.Show(tokenstr); } }
相关文章推荐
- 两种 HTTP 请求方法:GET 和 POST
- HTTP访问控制(CORS)
- Python CGI编程和CGIHTTPServer
- PHP模拟发送POST请求之一、HTTP协议头部解析
- Netscape HTTP Cookie File php程序中用curl保存的cookie文件格式
- win7如何添加网络打印机和共享网络打印机
- HTTP所承载的货物(图像、文本、软件等)要满足的条件
- java网络编程——Socket和ServerSocket,套接字编程——简单聊天室
- 一个简单的网络验证程序的分析
- 从网络下载的图片加缓存功能
- httpclient
- Http Response Code[整理]
- Http 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete
- 网络字节序与主机字节序
- 保护HTTP的安全
- 创建安全的基于HTTP的api应用接口
- TCP/IP
- [Servlet]HttpServletResponse的二进制输出(获取应用程序中的资源再输出)、重定向、错误发送
- HTTP深入浅出 http请求(转)
- 10月第4周网络安全报告:放马站点.COM占75.8%