连接的主机无法响应(内部NAT地址)

时间:2010-04-28 18:59:35

标签: c# web-services certificate

我正在编写第一个连接到基于XML的服务的C#Web应用程序。它要求我提供证书并提供XML流。它似乎正确验证,但它给出了以下错误:

  

连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应10.1.10.4:3128

有趣的是,我不是代理人或类似的东西。我正在直接连接到互联网。有一次,我确实使用了具有内部NAT地址的代理。

所以我的问题是:Visual Studio是否有某种我需要更改的默认代理设置?此IP不再用于任何内容,因此我知道我不需要使用任何代理身份验证代码。

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Uri requestURI = new Uri("*site omitted*");

            //Create the Request Object
            HttpWebRequest pageRequest = (HttpWebRequest)WebRequest.Create(requestURI);

            //After installing the cert on the server export a client cert to the working directory as Deluxe.cer
            string certFile = "*certificate omitted*";
            X509Certificate cert = X509Certificate.CreateFromCertFile(certFile);

            //Pull in your Data, if it is from an external xml as below or create an xml string with variables if a dynamic post is required.
            string xmlPath = "*XML omitted*";
            System.Xml.XmlDocument passXML = new System.Xml.XmlDocument();
            passXML.Load(xmlPath);

            //XML String with the data needed to pass
            string postData = passXML.OuterXml;

            //Set the Request Object parameters
            pageRequest.ContentType = "application/x-www-form-urlencoded";
            pageRequest.Method = "POST";
            pageRequest.AllowWriteStreamBuffering = false;
            pageRequest.AllowAutoRedirect = false;
            pageRequest.ClientCertificates.Add(cert);
            postData = "xml_data=" + Server.UrlEncode(postData);
            pageRequest.ContentLength = postData.Length;

            //Create the Post Stream Object
            System.IO.StreamWriter postStream = new System.IO.StreamWriter(pageRequest.GetRequestStream());

            //Write the data to the post stream
            postStream.Write(postData);
            postStream.Flush();
            postStream.Close();

            //Set the Response Object
            HttpWebResponse postResponse = (HttpWebResponse)pageRequest.GetResponse();

1 个答案:

答案 0 :(得分:0)

您要了解正在发生的事情的唯一方法是使用Fiddler或Microsoft Network Monitor查看网络流量。