Solved

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

Posted on 2013-12-18
3
1,437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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