1

I am using xml.net in web application When I try load xml through an http internet url using: xmlDoc.Load("http://....") i get an error:"connected host has failed to respond"

Anyone knows the fix for this?

Thanks

7 Answers 7

2

Connected Host has failed to respond is because you've not go the uri correct or you're not allowed to access it, or it's not responding to you, or it's down. http doesn't really care what it transmits.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, try putting the URL in IE first. If it is supposed to return XML then it should show the XML inside of the browser.
1

It probably means exactly what it says: the web server responsible for requests at the URL you specify isn't sending back responses. Something's going wrong on the web server, and if so, you can't do anything about someone's web server out there in the cloud not functioning properly.

You can, however, accept the fact that not every URL will work, and that you'll have to catch the Exception that the XmlDocument or XDocument is throwing. It's reasonable to expect that this scenario may occur. Thus, you need to programming defensively and by including the appropriate exception handling to handle such cases.

EDIT: So you can access it from outside the .NET framework eh? Perhaps try using an HTTP debugger, like Fiddler, and compare the request your XML document object makes to the request your browser makes. What header fields are different? Is there a header that the browser includes that the XML document object doesn't? Or are there different header values between the two, that may be causing the .NET request not to be responded to? Go figure.

Comments

0

If the page is accessible through a web browser but not through the load method it sounds as like the method isn't making a proper HTTP Request to the web server for the page wanted.

You can try using an HTTPWebRequest with a standard GET method to make a proper HTTP request for the webpage. You can then pass the response to the XMLDocument.Load method as a stream and it should then load up fine.

HTTPWebRequest Class MSDN.com

Comments

0

Try making a WebRequest to the url and set its UserAgent property to something like "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)" . If it works load the text you get in the xmldoc.

Comments

0

I tried loading the xml using .Net HttpWebRequest and also tried setting the userAgent property. But its still giving me the error message: "Unable to connect to the remote server" The xml is however accesible through the browser.

Here is the code:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

    request.UserAgent ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)";

    string result = string.Empty;

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
            // Get the response stream
            StreamReader reader = new StreamReader(response.GetResponseStream());

            // Read the whole contents and return as a string
            result = reader.ReadToEnd();

    }

Thanks.

Comments

0

Is there any proxy being used by your browser?

just try telnet to see if you are able to connect to the web server by an application other than the browser.

so if you are using a url like http://www.xmlserver.com/file.xml then try the following in command prompt:

                 telnet xmlserver.com 80

Comments

0

A big difference between your request and a browser request could be bridged with the following line:

request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.