Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

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

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)

%>
Avatar of Vikram Singh Saini
Vikram Singh Saini
Flag of India image

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.
Avatar of hankknight

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial