'.NET httpclient 406 not acceptable

I am trying to make a http get call using .NET and I am getting 406 Not accepted error. The same request when I try to do from PostMan its working fine! I have tried verifying my headers and also mapped it with the same postman request (including the postman's hidden auto-generated headers. Tried with different accept headers also. Nothing worked, can someone point me in some direction how I can identify the issue. Unfortunately I dont have any control over the server endpoint.

My .NET console app code is this!

            HttpClient httpClient = new HttpClient();
            httpClient.BaseAddress = new Uri(BaseURL + "reports/1.0/");
            httpClient.DefaultRequestHeaders.Add("consumerKey", ConsumerKey);
            httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + AccessToken);
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("sessionToken ", ott);
            httpClient.DefaultRequestHeaders.Add("User-Agent", "PostmanRuntime/7.29.0");
            httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
            httpClient.DefaultRequestHeaders.Add("Connection", "keep-alive");
            httpClient.DefaultRequestHeaders.Add("Accept", "*/*");

            var response = await httpClient.GetAsync("orders");
            response.EnsureSuccessStatusCode();

Request from postman console looks like this. Request from postman console looks like this

Same request from Postman's raw log

GET /apim/reports/1.0/orders HTTP/1.1
consumerKey: L3UnAkofqNfW0rhgtYUz7UQzN58a
sessionToken: DA05DA9F178D8C0E5754F03E617A49546330776ABFDDBC
Accept: application/xml
Authorization: Bearer 6971ce62-789e-3b1b-b805-82560f1f21c6
Postman-Token: 04df336c-9226-4eab-8054-c004940e4660

HTTP/1.1 200 OK
Strict-Transport-Security: max-age=15768000; includeSubDomains
Access-Control-Expose-Headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Timestamp: 46
Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-    Type,SOAPAction,consumerKey,sessionToken,Authorization
Content-Type: application/json
Date: Sun, 22 May 2022 10:57:28 GMT
Transfer-Encoding: chunked

The failing request from Visual Studio seems like having 200 in the fiddler! Below is the response of failing request captured in fiddler.

HTTP/1.1 200 Connection Established
FiddlerGateway: Direct
StartTime: 18:13:22.888
Connection: close

This is a CONNECT tunnel, through which encrypted HTTPS traffic flows.
To view the encrypted sessions inside this tunnel, enable the Tools > Options > HTTPS > Decrypt HTTPS traffic option.

A SSLv3-compatible ServerHello handshake was found. Fiddler extracted the parameters below.

Here is the Visual Studio error I receive.

VS Error

Any suggestions on what can be the issue or how I can troubleshoot will be of great help! Please advise.



Solution 1:[1]

I faced the same issue in one project. It was due to two apis with same name and I haven't mentioned the request method. That's why server wasn't able to map the request to any of them try to look for the request method.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shubham Rathore