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();