Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-12-18
3
Medium Priority
?
1,590 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

886 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