WebClient stopped working after redirect
StewartBW
1,870
Reputation points
Hi
I enabled redirect for my website to forward www and non-www http requests to the https version.
After that, WebClient UploadValues (WebRequestMethods.Http.Post) stopped working while DownloadStringAsync and DownloadFileAsync still works as expected!
I pass the non-https version of my website URL to WebClient and expect that WebClient do the redirection automatically, DownloadStringAsync and DownloadFileAsync will follow the redirection correctly, while UploadValues won't!
A NotInheritable Class that Inherits WebClient did not help:
Protected Overrides Function GetWebRequest(ByVal address As System.Uri) As Net.WebRequest
Dim MyWR As Net.HttpWebRequest = CType(MyBase.GetWebRequest(address), Net.HttpWebRequest)
If MyWR IsNot Nothing Then
MyWR.AllowAutoRedirect = True
MyWR.MaximumAutomaticRedirections = 3
If _TimeoutSec = 0 Then
MyWR.Timeout = 30000
Else
MyWR.Timeout = _TimeoutSec * 1000
End If
End If
Return MyWR 'CType(MyWR, WebRequest)
End Function
Any idea how to fix it?
Thanks in advance.
Windows development | Windows API - Win32
Sign in to answer