My request isn't working correctly. I have a search box with a search button. Users can enter an address in the search box and then the address is sent out Google's API. But this isn't working for some reason. Does anyone know why? I will also include a pic of what the value of request
is when debugging.
private void RequestResponseHandler(IAsyncResult asyncResult)
{
HttpWebResponse response = null;
Stream responseStream = null;
try
{
response = (HttpWebResponse)request.EndGetResponse(asyncResult);
responseStream = response.GetResponseStream();
var xdoc = XDocument.Load(responseStream);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
The geocode API returns JSON. Example: https://maps.googleapis.com/maps/api/geocode/json?address=fifth%20avenue&key=AIzaSyCgsNpuUoH7m6U7lqeZjlLZ3MgM15PW15oBut here you are trying to put this JSON into an XML document:
I would recommend you using a JSON parser instead.
Now that you have shown the actual exception it seems that in the environment in which you are working (Silverlight?) you don't have permission to access cross domain resources:
You are getting a
Security Error
because of this. Depending on the actual environment you are working with there might be different ways to resolve this issue. For example in Silverlight you might need to include aclientaccesspolicy.xml
file in order to make cross domain calls. In this file you need to explicitly allow the domains to which you need to make HTTP requests (in your case that would bemaps.googleapis.com
).