PDA

View Full Version : C# WebRequest exception



fadishouha
29 Oct 2010, 09:20 AM
Hi,

I've created a website in .NET/C#
I'm using the WebRequest class to send an HTTP request to a remote server. It's working fine on my PC (locally), but when I upload and test my site on the hosting server it throws this exception:

The remote name could not be resolved: remote_server_name

Here is my source code:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string responseText = readStream.ReadToEnd();
response.Close();
readStream.Close();

please.. anyone can help ??

Alan
29 Oct 2010, 10:26 AM
What is the query you're injecting into the WebRequest.Create method?

I assume it's a url, which it should be getting the host automatically from. Try setting the host manually:



HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query);
request.host = "remote_server_name";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();


If that still doesn't work, then it could be an issue with your IIS configuration or web.config.