Click here to Skip to main content
15,607,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have windows application in which accessing a rest api in it.while running the windows application i am getting the following error.
The remote server returned an error: (403) Forbidden.

Here is my code.

string URL = Convert.ToString(ConfigurationManager.AppSettings["GetDimensionsApi"]);
               var httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
               httpWebRequest.ContentType = "application/json";
               httpWebRequest.Method = "GET";
               httpWebRequest.ContentLength = 0;
               var result = "";
               var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
               using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                   result = streamReader.ReadToEnd();
                   var deserialized_json = JsonConvert.DeserializeObject(result);
                   var response = (dynamic)(deserialized_json);
                   var Dimensions_data = response.ListDimensions;

                   if (Dimensions_data.Count>0)
                       foreach (var items in Dimensions_data)
                           DataRow row = dt.NewRow();
                           row["Sno"] = Convert.ToInt32(;
                           row["Dimensions"] = Convert.ToInt32(items.Width) + "*" + Convert.ToInt32(items.Height);


Thanks in advance

What I have tried:

I have tried by giving read write permissions to webapi project in iis server.but still i am facing the issue
Updated 18-Jul-22 3:36am
George Swan 18-Jul-22 10:35am    
Have you tried debugging the 403 error in your browser? In Chrome, the debugger is at more tools/developer tools

1 solution

The problem is exactly what it seems: your user does not have permission to access the URL you are requesting.

Chances are you need to login somehow to the remote site - start by talking to the admins and see what they can do to help you.
Share this answer

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