none
Course 18 compile discrepancy "URL formats not supported" RRS feed

  • Question

  • Input code exactly as course 18 indicated.

    Compiler throws "url format not supported" At this point resolving error beyond my capabilities.

    Code follows:

    Imports System.Net

    Module Module1

        Sub Main()


            Dim client As WebClient = New WebClient()
            Dim reply As String = client.DownloadString("http:/www.devu.com") 'compiler throws error
            Console.WriteLine(reply)                                                                'url formats are not supported 
            Console.ReadLine()
        End Sub

    End Module

    Thursday, November 16, 2017 8:42 PM

Answers

  • Hi Alas34973,

    Based on your code, I found that you gave the URL a bit of formatting error above, please replace / with //, then you can try it again.

     Dim client As WebClient = New WebClient()
             Dim reply As String = client.DownloadString("http://www.devu.com") 'compiler throws error
             Console.WriteLine(reply)  

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Monday, November 20, 2017 12:55 AM
    • Marked as answer by Alas34973 Monday, November 20, 2017 2:30 PM
    Friday, November 17, 2017 5:58 AM
    Moderator

All replies

  • Alas,

    Try it a little differently:

    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, _
                               e As System.EventArgs) _
                               Handles MyBase.Load
    
            Dim desktop As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            Const url As String = "http://www.fls-online.net/VBNet_Forum/index.htm"
    
            Dim fi As New IO.FileInfo(IO.Path.Combine(desktop, "DownloadedFile.htm"))
    
            If fi.Exists Then
                fi.Delete()
            End If
    
            Using wc As New System.Net.WebClient
                Dim remoteString As String = wc.DownloadString(url)
    
                If Not String.IsNullOrWhiteSpace(remoteString) Then
                    IO.File.WriteAllText(fi.FullName, remoteString)
                End If
            End Using
    
            Stop
    
        End Sub
    End Class


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 16, 2017 8:55 PM
  • Thank you Mr. Smith!

    Working from MS Virtual Academy Courses for Absolute beginners makes it difficult to get a handle on the modern coding concepts.

    Friday, November 17, 2017 5:16 AM
  • Hi Alas34973,

    Based on your code, I found that you gave the URL a bit of formatting error above, please replace / with //, then you can try it again.

     Dim client As WebClient = New WebClient()
             Dim reply As String = client.DownloadString("http://www.devu.com") 'compiler throws error
             Console.WriteLine(reply)  

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Monday, November 20, 2017 12:55 AM
    • Marked as answer by Alas34973 Monday, November 20, 2017 2:30 PM
    Friday, November 17, 2017 5:58 AM
    Moderator
  • Thank you Mr. Smith!

    Working from MS Virtual Academy Courses for Absolute beginners makes it difficult to get a handle on the modern coding concepts.

    I'm just Frank. ;-)

    I'm glad that it helped but do you understand what I have there?

    The easiest way (for me at least) to think about the DownloadString method is to think of it as a "reader". Since it "reads" a string that's online, make sure the URL ends up being something that can be read as text.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Friday, November 17, 2017 1:13 PM