Solved

ASP.NET/VB: Username and password with WebClient()/DownloadString

Posted on 2013-12-18
3
1,419 Views
Last Modified: 2015-01-05
How can I avoid this error?
The remote server returned an error: (401) Unauthorized.

The username is "userx" and the password is "passwordx".

<%@ Page Language="VB"%>
<%@Import namespace="System"%>
<%@Import namespace="System.Web"%>
<%@Import namespace="System.Net"%>
<%@Import namespace="System.IO"%>
<%@Import namespace="System.Text"%>
<%

Dim data As String
Using WC As New System.Net.WebClient()
 data = WC.DownloadString("https://example.com.com/")
End Using
HttpContext.Current.Response.Write(data)

%>
0
Comment
Question by:hankknight
3 Comments
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 39727062
Hi,

The possible reason could be that your default web.config (the system one) is configured to check authenticity of users.

Or you had set some settings in IIS that is restricting you from accessing web page directly without authentication. I am not getting that setting name in my mind.
0
 
LVL 16

Author Comment

by:hankknight
ID: 39727127
Using ASP.NET I want to grab the contents of this page:
http://www.pagetutor.com/keeper/mystash/secretstuff.html

Username: jimmy
Password: page

This does not work:
<%@ Page Language="VB"%>
<%@Import namespace="System"%>
<%@Import namespace="System.Web"%>
<%@Import namespace="System.Net"%>
<%@Import namespace="System.IO"%>
<%@Import namespace="System.Text"%>
<%

Dim data As String
Using WC As New System.Net.WebClient()
 ' Username: jimmy
 ' Password: page
 data = WC.DownloadString("http://www.pagetutor.com/keeper/mystash/secretstuff.html")
End Using
HttpContext.Current.Response.Write(data)

%>

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39735762
...
WC.Credentials = new System.Net.NetworkCredential("jimmy", "page")
data = WC.DownloadString("http://www.pagetutor.com/keeper/mystash/secretstuff.html")
...

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question