-3

I have a legacy .NET 4.8 framework project.

I have tried to get these headers:

Accept-Encoding
CacheControl 

sent to my endpoint.

But looking with Fiddler, they are not sent, even if I explicitly set them. Any idea why?

HttpRequestMessage TmpRequest = new HttpRequestMessage(HttpMethod.Get, url);

TmpRequest.Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0");

TmpRequest.Headers.AcceptEncoding.ParseAdd("gzip");
TmpRequest.Headers.AcceptEncoding.ParseAdd("deflate");
TmpRequest.Headers.AcceptEncoding.ParseAdd("br");

TmpRequest.Headers.CacheControl = new CacheControlHeaderValue
                    {
                        NoCache = true
                    };

HttpResponseMessage TmpResponse = await TmpClient.SendAsync(TmpRequest);

Only the UserAgent is sent as header...

But why not Accept-Encoding and CacheControl ?

Here is what fiddler shows :

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
3
  • Then I inspect the TmpRequest just before TmpRequest like this TmpRequest.ToString() i see the following : Cache-Control: no-cache Accept-Encoding: gzip, deflate, br User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0 So the values are there but not sent. Very strange... Commented Nov 23 at 15:08
  • Do note that you can edit your question and add it the information that you believe is relevant Commented Nov 24 at 19:30
  • I just tried your code, in a .NET 4.8 console app with fiddler and it worked fine (where url=localhost:8888). The only line that could be different would be HttpClient TmpClient = new HttpClient(); Does Fiddler startup as the system proxy? Is Options->Connections->Act as system proxy on startup checked? Commented 2 days ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.