当试图调用谷歌位置来寻址服务时,它给了我这个消息:
无法建立连接,因为目标机器主动拒绝它 173.194.66.95:80
我将 ASP.net 4 与 C# 一起使用。
这是我的代码:
protected void btn_FindAddress_Click(object sender, EventArgs e)
{
url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=";
query = LatY.Text + "," + LongX.Text + "&sensor=true";
Address.Text = url;
Uri uri = new Uri (url + query);
// Create a request for the URL.
WebRequest request = WebRequest.Create(uri);
//// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Status.Text = (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Address.Text = responseFromServer;
// Clean up the streams and the response.
reader.Close();
response.Close();
}