4

I am trying to download a response from a certain website in order to confirm the site is up and to measure the response time (which is provided in the site content)

The page has url like https://www.blabla.com.au/ServiceAvailability

I can put in the page url in my browser and I can see the page is up and response time provided. I can also click the link and the page will load in the visual studio browser as well.

But when I try to call the same url from my application I get the following System.Net.WebException:

{"The remote name could not be resolved: "www.blabla.com.au"}

The code is running on my local PC, I am also accessing the website from my local PC and can bring up the page from the browser and in VS

My code looks like this:

string myUrl ="https://www.blabla.com.au/ServiceAvailability";

using (WebClient webClient = new WebClient())
{ 
    result = webClient.DownloadString(myUrl);
}

where result is a string

I have tried the following to get around the problem:

  1. Run visual studio as an administrator
  2. Use my user name/ password as credentials instead of the default
  3. Put an @ infront of the url
  4. Tried using WebRequest and HttpWebRequest as per code blocks below:

    WebRequest req = WebRequest.Create(myUrl);
    res = req.GetResponse();
    
    HttpWebRequest req = WebRequest.Create(myUrl) as HttpWebRequest;
    HttpWebResponse res = req.GetResponse() as HttpWebResponse;
    
alex.b
  • 4,547
  • 1
  • 31
  • 52
fgenc
  • 133
  • 1
  • 1
  • 7
  • may be ssl could be an issue. do you need add a ssl certificate with the request? – qamar May 12 '14 at 03:12
  • Hi Aleksey, I don't think so because I have also tried using http://www.google.com.au as my url address – fgenc May 16 '14 at 06:19

1 Answers1

5

One possibility is your browser uses some proxy where your code does not (or use different one).

If it is the case make sure to set WebClient.Proxy property to match one in the browser.

If it is not proxy issue - check if DNS resolves correctly via external tools (like http://mxtoolbox.com/DNSLookup.aspx) - it is unlikely, but possible if browser uses different DNS than your code.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • I think your answer is on the right track, I will try it out and vote your answer up if it turns out to be the issue – fgenc May 16 '14 at 06:21
  • 3
    I was able to resolve my issue by making use of the WebProxy class `using (WebClient webClient = new WebClient()) { webClient.Proxy = new WebProxy("myproxy.com"); result= webClient.DownloadString(someURL);}` – fgenc Aug 04 '14 at 00:52
  • I got the same exception when trying to load [wikipedia] (http://www.en.wikipedia.org/). When debugging i found that the link was changed to "www.en.wikipedia.org" somehow. Tested the link(https://www.en.wikipedia.org/) in http://mxtoolbox.com/DNSLookup.aspx and that confirms that is down. Any reason why? – Lucas Palma Stabile Jun 20 '17 at 21:00
  • @LucasPalmaStabile feel free to ask new question instead of comment. – Alexei Levenkov Jun 20 '17 at 23:47
  • How can you find what the browser is using to plug into this? Thanks. – Adam Garner Aug 03 '17 at 15:40
  • @AdamGarner https://stackoverflow.com/questions/8808052/c-sharp-getting-proxy-settings-from-internet-explorer and similar question should answer that. Otherwise please ask separate question. – Alexei Levenkov Aug 03 '17 at 18:24