Question Background:
I am attempting to make a simple HttpWebRequest
to a Web API that I have hosted in Azure.
The Issue:
If I access my Web API end point through a browser or a request tool such as Postman I am receiving a JSON
response with no Issues.
If I try accessing the same end point through a HttpWebRequest
Call I receive a 500 fatal error but I am able to see in the response property of the Try Catch
that the JSON
response has been returned.
The remote server returned an error: (500) Internal Server Error.
The Code:
The following is the simple request I am making to the Web API I have. As stated before, in the Catch
the response is returning back the JSON
I expect, as shown:
{"ResponseMessage":"OK","ResponseContent:[{"kind":"youtube#playlistItem","etag":"\"gMxXHe- ........ etc }]}
The Request:
string url ="http://myapi.azurewebsites.net/api/videos/GetYouTubeVideos";
try
{
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
WebResponse wr = req.GetResponse();
}
catch (WebException wex)
{
var pageContent = new StreamReader(wex.Response.GetResponseStream())
.ReadToEnd();
}
I appreciate that identifying the cause of a 500 isn't straight forward but can anyone provide a reason I would be getting this error but also still receiving the JSON
from the service that is apparently throw an exception?