Solved

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

Posted on 2013-12-18
3
1,359 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 74

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now