CyberLex
asked on
WebClient with HTTPS and Credentials
Greetings all!
I'm trying to download html as text from a website and I'm using the WebClient downloadstring to do this. A problem now arises if the website is protected with htaccess AND using HTTPS at the same time, I allways get a 401 unauthorized back. Just to note, the website is NOT protected with a login-form, when I browse to the site the IE credentials window pops up.
- No username/pw, HTTP - works fine
- With username/pw, HTTP - works fine
- No username/pw, HTTPS - works fine
- With username/pw AND HTTPS - I allways get 401 unauthorized back and I have no clue why. I browsed the web, there seem to be multiple ppl having the very same problem, but no answers. Using VS2010, visual basic, .net 3.5
What I need to add is that the HTTPS certificate of the site is invalid and I skip it by implementing my own ServicePointManager.Server Certificat eValidatio nCallback which just returns true no matter what.
I also tried out various cachepolicies but to no success. Any hint/direction is very much appreciated.
Thanks
Lex
I'm trying to download html as text from a website and I'm using the WebClient downloadstring to do this. A problem now arises if the website is protected with htaccess AND using HTTPS at the same time, I allways get a 401 unauthorized back. Just to note, the website is NOT protected with a login-form, when I browse to the site the IE credentials window pops up.
- No username/pw, HTTP - works fine
- With username/pw, HTTP - works fine
- No username/pw, HTTPS - works fine
- With username/pw AND HTTPS - I allways get 401 unauthorized back and I have no clue why. I browsed the web, there seem to be multiple ppl having the very same problem, but no answers. Using VS2010, visual basic, .net 3.5
What I need to add is that the HTTPS certificate of the site is invalid and I skip it by implementing my own ServicePointManager.Server
I also tried out various cachepolicies but to no success. Any hint/direction is very much appreciated.
Thanks
Lex
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf MyCertValidationCb) 'just returns true to skip invalid certificate
Dim wr As New WebClient
wr.Credentials = New NetworkCredential("myUser", "myPass")
mystring = wr.DownloadString(myURL)
'Works perfectly fine with http and username/pw or https with no username/pw, but not with username/pw AND https.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER