Click here to Skip to main content
14,775,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm on a proxy and I get a WebException while calling a method which should return HTTP response in JSON format.

The error is the following:

Server Error in '/' Application.
404
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: 404

Source Error:

Line 44:             else
Line 45:             {
Line 46:                 throw new WebException(((int)response.StatusCode).ToString());
Line 47:             }
Line 48:         }


What I have tried:

private T GetResult<T>(HttpResponseMessage response)
        {
            if (response.IsSuccessStatusCode)   // code 200
            {
                var content = response.Content.ReadAsStringAsync().Result;   
                return JsonConvert.DeserializeObject<T>(content);
            }
            else
            {
                throw new WebException(((int)response.StatusCode).ToString());
            }
        }
Posted
Updated 27-Nov-20 6:42am

1 solution

404 points to unauthorized, I would download Postman and try it in there 1st. Try that before code
   
Comments
Richard Deeming 30-Nov-20 5:21am
   
404 is "not found".

Either 401 or 403 would be authentication / authorization errors.
xhon 2-Dec-20 8:29am
   
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900