.net - 在后台运行的 Fiddler 修复了访问令牌的 HttpPost。也在邮递员工作
问题描述
我无法在 .NET 控制台应用程序中获取访问令牌。我写了一个失败的单元测试。
但是,如果我在后台运行 fiddler 来解密 https 请求,则该帖子可以从邮递员那里使用,也可以在控制台应用程序中使用。
我不知道为什么提琴手让它工作,但如果它正在运行,我会得到一个访问令牌
我得到的错误是“在数据库配置文件中找不到数据库 *****”或“Client_id 或 Client_secret 无效”
代码如下:
var url = _baseUrl + "token";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
var grantType = "password";
var integrated = "N";
var username = ConfigurationManager.AppSettings["Deltek.Username"];
var password = ConfigurationManager.AppSettings["Deltek.Password"];
var database = ConfigurationManager.AppSettings["Deltek.DatabaseName"];
var clientId = ConfigurationManager.AppSettings["Deltek.ClientId"];
var clientSecret = ConfigurationManager.AppSettings["Deltek.ClientSecret"];
Dictionary<string, string> values = new Dictionary<string, string>();
values.Add("username", username);
values.Add("password", password);
values.Add("grant_type", grantType);
values.Add("integrated", integrated);
values.Add("database", database);
values.Add("client_Id", clientId);
values.Add("client_secret", clientSecret); // _keyvaultservice.getSecret(keyvault + secretname)
var content = new FormUrlEncodedContent(values);
request.Content = content;
ServicePointManager.SecurityProtocol =SecurityProtocolType.Ssl3 |SecurityProtocolType.Tls12;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager
.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;
var response = await _client.SendAsync(request);
string json = await response.Content.ReadAsStringAsync();
return await response.Content.ReadAsAsync<DeltekToken>();
解决方案
推荐阅读
- postgresql - 遍历数组参数并插入它们
- bash - Shell echo 语句输出
- kdb - 如何计算 KDB 中的对数?
- go - 如何从 opentracingsSpan 获取操作名称?
- python - Pandas:使用 iterrows 应用更改
- ruby-on-rails - 尝试重新部署旧应用程序时出现 Heroku 错误
- amazon-s3 - 用于 S3 中 PARQUET 格式的 Kafka S3 源连接器
- python - 使插入的 Matplotlib 图具有正确的尺寸
- ios - iOS SiriKit:仅语音响应?
- node.js - Firebase 实时数据库简单选择查询极慢