I am trying to access a REST web service but get an error HTTP 500. There must be something I am not doing correct but couldn't find out. It is a publicly available service, otherwise I would have gotten a 403 error.
Here is my code: (url is a string containing the web service URL, param is a string containing the parameters.)
string url = @"http://crimemapping.edmontonpolice.ca/DataProvider.asmx/getOccurrenceInfo";
string param = "{\"method\":\"send\",\"params\":[\"neighbourhoodID\":\"2\",\"crimeTypes\":\"Assault\",\"strStartDate\":\"2011,12,02\",\"strEndDate\":\"2012,03,01\"]}";
// Reassigning param to increase readability.
param = @"{""method"":""send"",""params"":[""neighbourhoodID"":""2"",""crimeTypes"":""Assault;Sexual Assaults;Break and Enter;Theft From Vehicle;Homicide;Theft Of Vehicle;Robbery;Theft Over $5000"",""strStartDate"":""2012,02,01"",""strEndDate"":""2012,03,01""]}";
string response;
WebRequest request = WebRequest.Create(url);
request.Method = "POST"; //REST based-services using Post method
request.ContentType = "application/json"; //tells request the content typs is JSON
request.ContentLength = param.Length;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
requestWriter.Write(param);
requestWriter.Close();
StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream());
response = responseReader.ReadToEnd();
responseReader.Close();
What I couldn't figure out in the beginning was that the JSON request cannot be made by any IP. It checks the IP before proceeding. The error I was getting was way off, so didn't help much.
Thanks all.