首页 > 解决方案 > Getting 403 Forbidden for the same request to server in second time

问题描述

I using HttpClient object make an http call to retrieve audio content of file. Somehow same request works for first time but when i seek the content and make the new request with same set of headers i am getting 403 Forbidden error.

I just don't understand what exactly causing the error. I tried to set User-agent in DefaultRequestHeaders but nothing is working.

await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);

Response Header ContentType = application/vnd.apple.mpegurl Set-Cookie = some value

Please suggest me what could be wrong

标签: c#multithreadinghttpclienthttp-status-code-403

解决方案


尝试清除 HTTP 客户端标头。我遇到了同样的问题,然后清除了 HTTP 客户端标头并且它起作用了。

httpClient.DefaultRequestHeaders.Clear();

在发送请求之前应该解决问题。


推荐阅读