Results 1 to 15 of 15

Thread: [RESOLVED] WebException : Remote Name could not be resolved Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Resolved [RESOLVED] WebException : Remote Name could not be resolved Error

    I am trying to read in a Web Page, using the code below.

    However it keeps failing when it runs the line s = client.OpenRead(remoteUri)

    The error I am getting is

    The remote name could not be resolved: http://msdn.microsoft.com'

    Can anyone offer any suggestions.

    Code:
    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text.RegularExpressions
    Module Module1
    
        Sub Main()
            '  Specify the URI of the resource to parse.
            Dim remoteUri As String = "http://msdn.microsoft.com/en-gb/default.aspx"
    
            '  Create a WebClient to perform the download.
            Dim client As New WebClient
    
            Console.WriteLine("Downloading {0}", remoteUri)
            Dim s As System.IO.Stream
            Try
                s = client.OpenRead(remoteUri)
            Catch ex As Exception
                Debug.Print(ex.Message)
                Debug.Print(ex.ToString)
                End ' Halts as no use continuing if we cannot connect to site. 
            End Try
            Dim r As String
            Dim sr As System.IO.StreamReader = New System.IO.StreamReader(s, System.Text.Encoding.UTF7, False)
            r = sr.ReadToEnd()
    
            '  Perform the download getting the resource as a string.
            Dim str As String = client.DownloadString(remoteUri)
    
            '  Use a regular expression to extract all fully qualified
            '  URIs that refer to JPG files.
            Dim matches As MatchCollection = Regex.Matches(str, "http\S+[^-,;:?]\.jpg")
    
            '  Try to download each referenced .JPG files.
            For Each expMatch As Match In matches
                For Each grp As Group In expMatch.Groups
                    '  Determine the local filename.
                    Dim downloadedFile As String = grp.Value.Substring(grp.Value.LastIndexOf("/") + 1)
    
                    Try
                        '  Download and store the file.
                        Console.WriteLine("Downloading {0} to file {1}", grp.Value, downloadedFile)
    
                        client.DownloadFile(New Uri(grp.Value), downloadedFile)
                    Catch ex As Exception
                        Console.WriteLine("Failed to download {0}", grp.Value)
                    End Try
                Next
            Next
    
            '  Wait to continue.
            Console.WriteLine(Environment.NewLine)
            Console.WriteLine("Main method complete.  Press Enter.")
            Console.ReadLine()
    
        End Sub
    
    End Module
    Last edited by Torc; Nov 24th, 2009 at 04:21 AM. Reason: Inserted Newline on Catch ex As Exception
    Signature Under Construction

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: WebException : Remote Name could not be resolved Error

    Why don't you use just the WebClient.DownloadString method?
    Having said that, your problem is DNS related. I'd check and make sure that your DNS server is functioning properly.
    Last edited by stanav; Nov 23rd, 2009 at 03:48 PM.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: WebException : Remote Name could not be resolved Error

    Just an FYI, that I do not get an exception when I run that code, and it resolves fine for me.

    Did you try a different URL to make sure it is not an issue with that specific URL and maybe your internet provider? I mean, I am assuming you can get there in a browser, but again, I don't get the exception you do when I do an OpenRead on that URL.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: WebException : Remote Name could not be resolved Error

    Hi stanav,

    When I try to use client.DownloadString I get the same error.

    I got this code from a VB 2008 Recipe book, it is almost exactly the same, with the exception of enclosing the s = client.Openread(remoteUri) in a Try ... Catch.

    Hi kleinma,

    I have tried a number of different URL's, including the good old www.vbforums.com, but I get the same result with each; I did make sure that I could reach each URL I tried in my browser first.

    I have even created a Windows Form App with just a Web Browser control, but cannot
    load any web pages, I get Navigation Cancelled.

    I am in the process of teaching myself VB.Net and this is the first time I have tried to connect to the Web.

    Some of the posts I could find on this start talking about Proxies, which I have not come across before, and the posts get too technical for me without any knowledge of Proxies.
    Signature Under Construction

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: WebException : Remote Name could not be resolved Error

    If you can reach the webpage using a web browser but not in your program, it's most likely that your friewall is blocking your program from accessing the Internet. Try turning off the firewall and see if it works.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: WebException : Remote Name could not be resolved Error

    You could have an LSP problem. (corrupted Winsock stack). I have seen this prevent .NET code from accessing the web, while things like IE (or other browser) still worked fine. It is possible this is your issue, but no way for me to be sure.

    You could try resetting your winsock stack and seeing if that fixes anything for you. If you are running Win XP SP2 or higher, you can open a command prompt and run

    netsh winsock reset

    You will need to reboot. If that doesn't fix it, then it could be a sign of a bigger issue on your system.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: WebException : Remote Name could not be resolved Error

    Hi kleinma & stanav,

    I ran the command netsh winsock reboot and rebooted but still had the problem.

    Although I was reluctant to remove my firewall, I did so temporarily, and am now running a full Virus Scan (Paranoia Rules), The result however was that I was able to get past the s = client.OpenRead(remoteUri).

    Do you have any suggestions as to how I can grant access to my program, whilst developing it, in such a way as to avoid taking down my Firewall.
    Signature Under Construction

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: WebException : Remote Name could not be resolved Error

    It depends on the specific firewall usually as to what settings it offers.

    You may just be able to designate some sort of global "anything that runs from my projects folder is allowed through the firewall" sort of rule, but it depends on if it offers such functionality.

    Just allowing the exe generally doesn't work because each time you rebuild and run your code, the firewall will consider it a new exe.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: WebException : Remote Name could not be resolved Error

    I am using McAfee, and I cannot seem to add permission for a directory, it looks like it has to be for a specific program.

    Any suggestions?
    Signature Under Construction

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: WebException : Remote Name could not be resolved Error

    Yes, get rid of McAfee

    I can tell you that the free firewall software from Comodo is likely better anyway, and does offer features such as defining an "important files/folders" group and adding that group as a firewall exception.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: WebException : Remote Name could not be resolved Error

    Nice suggestion, unfortunately I cannot get rid of McAfee for the foreseeable future.
    Signature Under Construction

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: WebException : Remote Name could not be resolved Error

    Company requirement?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: WebException : Remote Name could not be resolved Error

    Sort of, it is a Home computer, but we receive E-Mails from a company which has certain security requirements.
    Signature Under Construction

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: WebException : Remote Name could not be resolved Error

    A company that sends you emails require that you have mcafee firewall installed? Sounds a bit odd to me, but you may just have to deal with turning the firewall off when you need to test code that connects to the web.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: WebException : Remote Name could not be resolved Error

    Hi Kleinma,

    Sorry for the late reply, been doing some testing and seem to have come up with the answer.

    In the McAfee Firewall Program Permissions I added all the .exe files, when I added the .vshost.exe file it came up stating that the program vshost.exe was blocked.

    In addition to this the Filename connected to the program was for another app I have worked on, when I granted Full Access my app worked, in fact when I removed my app from the Program Permissions, and just left the vshost.exe program it still worked.

    So problem solved.

    Many Thanks
    Last edited by Torc; Dec 3rd, 2009 at 10:55 AM. Reason: Accidentally posted before finished
    Signature Under Construction

Posting Permissions

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



Click Here to Expand Forum to Full Width