473,805 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebRequest returns 401 Unauthorized

I'm trying to make a webrequest to another server on our webfarm (to synch
the cache as explained in http://www.eggheadcafe.com/articles/20030420.asp)
but I'm getting a 401 unauthorized error.

We are using service accounts for the app to run under which I thought would
work in setting the webrequest's credentials property but with no luck....

HttpWebRequest req = (System.Net.Htt pWebRequest)Web Request.Create( sFullUri);
req.Method = "POST";
Stream stm = req.GetRequestS tream();
stm.Write(dataT oSend,0,dataToS end.Length);
stm.Close();
System.Net.WebR esponse resp;

string ServiceAcct =
System.Configur ation.Configura tionSettings.Ap pSettings["ServiceAcc t"];
string ServiceAcctPwd =
System.Configur ation.Configura tionSettings.Ap pSettings["ServiceAcctPwd "];

NetworkCredenti al nc = new NetworkCredenti al(ServiceAcct, ServiceAcctPwd, "");
req.Credentials = nc;
resp = req.GetResponse (); <!--error below...

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

Nov 19 '05 #1
1 3188
if your webservice is using ntlm, the service account needs to be a domain
account.

-- bruce (sqlwork.com)
"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
I'm trying to make a webrequest to another server on our webfarm (to synch
the cache as explained in
http://www.eggheadcafe.com/articles/20030420.asp)
but I'm getting a 401 unauthorized error.

We are using service accounts for the app to run under which I thought
would
work in setting the webrequest's credentials property but with no luck....

HttpWebRequest req =
(System.Net.Htt pWebRequest)Web Request.Create( sFullUri);
req.Method = "POST";
Stream stm = req.GetRequestS tream();
stm.Write(dataT oSend,0,dataToS end.Length);
stm.Close();
System.Net.WebR esponse resp;

string ServiceAcct =
System.Configur ation.Configura tionSettings.Ap pSettings["ServiceAcc t"];
string ServiceAcctPwd =
System.Configur ation.Configura tionSettings.Ap pSettings["ServiceAcctPwd "];

NetworkCredenti al nc = new NetworkCredenti al(ServiceAcct, ServiceAcctPwd,
"");
req.Credentials = nc;
resp = req.GetResponse (); <!--error below...

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

Nov 19 '05 #2

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

Similar topics

17
7243
by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values and in the debugger I can see the value I want in the property
2
9709
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url); WebResponse webResponse = webRequest.GetResponse(); beginStr = new StreamReader(webResponse.GetResponseStream(),
5
376
by: LOLO | last post by:
I want to save in a file the HTML code generated by a WebRequest to an aspx page. When a connect to a external site, i can obtain the html code generated by server. But when i connect to a page of my application, the server responds "(401) Non autorisé. " the is: WebRequest request=WebRequest.Create("http://localhost/software/tools/pages/index.htm"); WebResponse response=request.GetResponse(); Stream...
4
7238
by: Terry | last post by:
Hello, I am trying to get a response for an .aspx page in my current project (same virtual directory) by using WebRequest.GetResponse but I keep getting a exception with "500 Internal server error" in the exception message. I am able to do this fine with another .aspx page that has no code-behind. The page that has code-behind throws the exception. What I am doing is getting the .aspx response, reading the stream, replacing
2
8213
by: obeOnline | last post by:
I'm getting the following error... System.Net.HttpWebRequest.CheckFinalStatus() +676 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +139 System.Net.HttpWebRequest.GetResponse() +147 Web.WebDav.Page_Load(Object sender, EventArgs e)
0
1280
by: z. f. | last post by:
Hi, i have asp.net vb.net wep application. i try to investigate performance issue. so first i built a vb.net windows application that makes http requests to my pages and show me the time taken to receive the page and it's size. the windows app uses a WebRequest and StreamReader to receive the http request. the strange information is for a page that took to receive about 218 ms i enabled the trace in the web.config of my pages, and trace...
12
2871
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts the query string with no url encoding. I must pass the <> characters as they are in the query string. If these characters are url encoded the service rejects the request. This API Url is http://testing.shippingapis.com/ShippingAPITest.dll
0
942
by: KSC | last post by:
Hello, I am trying to access an ethernet temperature probe in my app. The probe is properly configured. Using IE I can access the data using the IPaddress & "/temp". This returns a string containing data from a number of temperature probes attached to the hub. For example: input "http://192.168.1.110/temp" returns "Probe 1|75.5|Probe 2|78.9|Probe 3|-99.9|Probe 4|-99.9"
0
1206
by: tascien | last post by:
Hi guys, when i use winhttp, and the server returns status 500, I get the text that the server returned anyway... when i use webrequest, and the server returns status 500, webrequest just throws an exception... How can i find the text that came back with the 500 status? I need this because i am posting to a web service, that returns soap
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.