New saved Uri symbols

I would like to instantiate a new Uri from a string containing escaped characters.

Dim sUri as String = "http://foo.bar/path/to/file_with%2fpercent?query=params"
Dim uUri as New Uri(sUri)
Console.WriteLine(uUri)

      

<R → →>
http://foo.bar/path/to/file_with/percent?query=params

      

How can I save %2f

?

+3


source to share


1 answer


use for example. the following code (note: only works for absolute urls!):



Sub DownloadFileToDisc (downloadUrl As String)
    Dim MyWebClient As New System.Net.WebClient()
    Dim downloadUri As New UriWithCorrectDataEncoding(downloadUrl)
    MyWebClient.DownloadFile(downloadUri, localFilePath)
End Sub

''' <summary>
''' Original behaviour of System.Uri.ToString returns unescaped characters in query parameters - a behaviour which corrupts URLs like http://domain.com/?forwardurl=module%3dInvoice%26action%3dCreatePDF4Mail%26return_module%3dInvoice into http://domain.com/?forwardurl=module=Invoice&amp;action=CreatePDF4Mail&amp;return_module=Invoice
''' </summary>
''' <remarks></remarks>
Private Class UriWithCorrectDataEncoding
    Inherits Uri

    Public Sub New(url As String)
        MyBase.New(url)
    End Sub

    Public Overrides Function ToString() As String
        Return MyBase.AbsoluteUri
    End Function

End Class

      

0


source







All Articles