首页 技术 正文
技术 2022年11月23日
0 收藏 557 点赞 3,980 浏览 1943 个字

VS2015 正式版中为什么没有了函数前面引用提示了?

 HttpClient _httpClient = new HttpClient();
var clientId = Config.GetValue("AuthUser");
var clientSecret = Config.GetValue("AuthPass"); var apiHost = Config.GetValue("ApiHost");
_httpClient.BaseAddress = new Uri(apiHost); var parameters = new Dictionary<string, string>();
parameters.Add("grant_type", "password");
parameters.Add("username", account);
parameters.Add("password", password); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(clientId + ":" + clientSecret))
); var response = await _httpClient.PostAsync("/token", new FormUrlEncodedContent(parameters));
var responseValue = await response.Content.ReadAsStringAsync();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var access_token = JObject.Parse(responseValue)["access_token"].Value<string>();
return new TokenResult() { Message = "ok", access_token = access_token };
//return JObject.Parse(responseValue)["access_token"].Value<string>();
}
else
{
var modelstate = JObject.Parse(responseValue)["ModelState"][].Value<string>();
return new TokenResult() { Message = modelstate };
} //string url = Config.GetValue("ApiHost") + "/token";
////设置HttpClientHandler的AutomaticDecompression
//var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip };
////创建HttpClient(注意传入HttpClientHandler)
//using (var http = new HttpClient(handler))
//{
// //使用FormUrlEncodedContent做HttpContent
// var content = new FormUrlEncodedContent(new Dictionary<string, string>()
// {
// {"grant_type", "password"},//键名必须为空
// { "username", account},
// {"password", password },
// }); // //await异步等待回应 // var response = await http.PostAsync(url, content);
// //确保HTTP成功状态值
// response.EnsureSuccessStatusCode();
// //await异步读取最后的JSON(注意此时gzip已经被自动解压缩了,因为上面的AutomaticDecompression = DecompressionMethods.GZip)
// var responseValue = await response.Content.ReadAsStringAsync();
// if (response.StatusCode == System.Net.HttpStatusCode.OK)
// {
// return JObject.Parse(responseValue)["access_token"].Value<string>();
// }
// else
// {
// return string.Empty;
// }
//}
上一篇: 1z0-052 q209_8
下一篇: CentOS 6.4 配置DNS
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849