473,378 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

WebRequests & 401 Unauthorized errors

Hi, I'm trying to make a WebRequest to url using the code below.

The url points to a large number XML files on my shared dev server via a virtual folder secured using basic authentication. I did this so I can run the application on my local machine and from the dev server but keep a single copy of the XML files only on dev server. The site uses Basic Authentication and both machines belong to the same domain

However, I ge

"The remote server returned an error: (401) Unauthorized. "

The weird thing this works when I run the code from the local machine all the time, but only ONCE from when I run the app on my dev server. Subsequent requests on the devserver's version return the 401 error. It's really strange in that it seems it loses my credentials on repeated requests. Suggestions on a fix or a better approach? Thanks, Dave

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://mydevserv:1027/Secure/ReportsVirtDir/14330.XML";)
HttpContext cxt = HttpContext.Current
NetworkCredential nc = new NetworkCredential(cxt.Request.ServerVariables["AUTH_USER"], cxt.Request.ServerVariables["AUTH_PASSWORD"],"")
req.Credentials = nc
WebResponse resp = req.GetResponse(); <--ERRO
StreamReader sr = new StreamReader(resp.GetResponseStream())
string strStream = sr.ReadToEnd();
Nov 18 '05 #1
0 1206

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newbie | last post by:
I have set up an ASP script (with some help from microsoft.public.inetserver.asp.general!) that grabs the windows username of the user and puts it into an Access database. It is setup on IIS5 as a...
0
by: Pmcg | last post by:
I would appreciate any help with the following, havn't found any answers for this in my research to date. I am trying to retreive a web page (a htm file intially) from a vdir on an intranet site...
2
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get...
4
by: Dave | last post by:
I've have several webrequests being called consecutively from an .aspx that return XML from sources outside the company. When the page runs it can take anywhere between 30-60 seconds. I heard...
2
by: Greg | last post by:
I've been reading a lot of other posts and trying a bunch of things but just cannot get this to work. I'm hoping someone can help. Here's the situation. I have a test folder which only...
2
by: Greg | last post by:
I've been reading a lot of other posts and trying a bunch of things but just cannot get this to work. I'm hoping someone can help. Here's the situation. I have a test folder which only...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
1
by: GM | last post by:
Hello, Is it possible to call 4 webrequests from an aspx file at the same time and then wait for the results of all 4 to come in. (4 webrequests to 4 different servers) I know that I can create...
0
by: Mudiya Dissa | last post by:
Hi, I have some code on my application like the following <% redirectUrl = "mypage.asp?type=100&id=something&view=10 'some more asp code
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.