Connected host failed to respond (internal NAT address)

Posted by MostRandom on Stack Overflow See other posts from Stack Overflow or by MostRandom
Published on 2010-04-28T18:59:35Z Indexed on 2010/04/29 1:17 UTC
Read the original article Hit count: 363

Filed under:
|
|

I'm writing my first C# web application that connects to an XML based service. It requires that I present a certificate and feed the XML stream. It seems to authenticate properly but then it gives the following error:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.1.10.4:3128

The funny thing is that I'm not on a proxy or anything like that. I'm connecting directly to the internet. At one point I we did use a proxy that with internal NAT address.

So my question is: Does Visual Studio have some sort of default proxy setting that I need to change? This IP is no longer used for anything, so I know that I don't need to use any proxy authentication code.

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about certificate