たとえば、次のコードを使用します(注意:絶対URLに対してのみ機能します!):
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&action=CreatePDF4Mail&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