Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复此错误调用google location to address Service“;目标机器主动拒绝了它”;_C#_Asp.net_Xml_Web Services_Google Api - Fatal编程技术网

C# 如何修复此错误调用google location to address Service“;目标机器主动拒绝了它”;

C# 如何修复此错误调用google location to address Service“;目标机器主动拒绝了它”;,c#,asp.net,xml,web-services,google-api,C#,Asp.net,Xml,Web Services,Google Api,当试图呼叫Google location to address服务时,它会给我以下消息: 无法建立连接,因为目标计算机处于活动状态 拒绝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=";

当试图呼叫Google location to address服务时,它会给我以下消息:

无法建立连接,因为目标计算机处于活动状态 拒绝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(); 
}

最常见的情况是,可以建立出站连接(可以访问远程服务器并及时发送响应),但您尝试使用的端口被阻止(防火墙或代理是我能想到的两个最可能的选项)

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