如何使用HttpClient设置标题

时间:2019-02-08 13:53:23

标签: c# rest api postman dotnet-httpclient

我在邮递员请求中有2个标头(不是授权),在C#应用程序中,我将获得与邮递员相同的值。 这是个好方法吗?

HttpClient client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

client.DefaultRequestHeaders.Add("PHASH", "6AD787BEE7E3D76BA9B98829BAEA5EA4");

client.DefaultRequestHeaders.Add("UHASH", 40EA4662B482319F8B21EDC378A09BF78CB364B5970E9F0965F816B8067DCF3A");

var uri = new Uri(url);
var response = await client.GetAsync(uri);

结果应该是HttpResponseMessage,但它使我出现此错误:

System.Net.Http.HttpRequestException: 'An error occurred while sending the 
request.'

Inner Exception
COMException : the text associated with this error code could not be found.

The host name in the certificate is invalid or does not match.

我不知道该错误是由于我的代码还是因为api。

0 个答案:

没有答案
相关问题