【发布时间】:2019-08-08 16:50:57
【问题描述】:
我收到以下错误
{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
Date: Mon, 05 Aug 2019 19:38:00 GMT
Server: Kestrel
X-Powered-By: ASP.NET
}}
这是我使用的代码
static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var paras = new Dictionary<string, string>
{
{"Authorization", "042a9ff198c04caf99161406f46e|API Testing"},
{"Content-Type", "application/json"}
};
var response = client.PostAsync("https://tsrvcis/cis-api/get-jrsc?format=json", new FormUrlEncodedContent(paras)).Result;
Debug.WriteLine(response);
}
虽然这里的授权是正确的,但我仍然未经授权。
【问题讨论】:
标签: c# asp.net .net asp.net-mvc .net-core