Results 1 to 2 of 2

Thread: C# WebRequest exception

  1. #1
    Join Date
    Feb 2010
    Posts
    5

    C# WebRequest exception

    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 ??

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    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:

    Code:
    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.
    “The best thing about a boolean is even if you are wrong, you are only off by a bit.”

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •