如何修复此错误调用google位置来解决服务“目标机器主动拒绝它”

时间:2012-08-09 12:58:49

标签: c# asp.net xml web-services google-api

尝试拨打Google地址以解决服务问题时,它会向我显示以下消息:

  

无法建立连接,因为目标计算机是主动的   拒绝了它173.194.66.95:80

我使用带有C#的ASP.net 4 这是我的代码:

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(); 
}

1 个答案:

答案 0 :(得分:2)

最常见的是,可以建立出站连接(远程服务器可以到达并且及时发送响应)但是您尝试使用的端口被阻止(a防火墙或代理是我能想到的两种最有可能的选择。)

可能来自于连接另一端没有服务器的事实:例如,如果您将NAT端口80连接到没有Web的系统,则可能会发生这种情况服务器。因为你正在调用谷歌的网址,我怀疑是这样,但我认为值得指出。