Hi,
I'm working with a mapquest App, and on the client side, i have the following Ajax Request:
$.ajax({
url: 'http://www.mapquestapi.com/search/v1/radius',
dataType: 'jsonp',
crossDomain: true,
data:
{
key: decodeURI('MyKey'),
origin: city + ', ' + state,
radius: 300,
hostedData: 'MyData',
maxMatches: 4
},
success: jsonResponse
});
For the above call, jsonResponse function kicks in and works perfectly well.
Now, i want to make this a server side routine in my ASP.NET MVC3 Web App.
I've Written the following code to imitate client side:
requestUrl = @"http://www.mapquestapi.com/search/v1/radius";
var request = HttpWebRequest.Create(requestUrl);
request.Method = "POST";
request.ContentType = "application/json";
var options = new
{
key = HttpUtility.UrlDecode("MyKey"),
origin = requestvm.City + "," + requestvm.State,
radius = 300,
hostedData = "MyData",
maxMatches = 4
};
var jsonobj = JsonConvert.SerializeObject(options);
try
{
using (StreamWriter requestWriter = new StreamWriter(request.GetRequestStream()))
{
requestWriter.Write(jsonobj);
}
}
catch (System.Net.WebException ex)
{
return null;
}
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
{
ModelState.AddModelError("", "Request Staus was not OK. Please try again");
return View(requestvm);
}
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
var serverResponse = reader.ReadToEnd();
var responseData = JsonConvert.DeserializeObject(serverResponse);
return null;
}
}
So when i do a breakpoint check var responseData, i get an error message from Mapquest, saying you need to provide the Key parameter. Can anyone tell me why the Key param is not working on the server side, but it is on the client?
Any suggestions are appreciated. Thanks.