Heybo Blog

If you look at me when I'm talking, you'll see what I'm saying ... about Tech and .NET discoveries!

My Links

News

Story Categories

Archives

Post Categories

Image Galleries

Login

Blog Stats

Links

Personal Websites

The request failed with HTTP status 401: Unauthorized

"System.Net.WebException: The request failed with HTTP
status 401: Unauthorized".

If you use an authentication on your webservice like Integrated Windows Authentication, you may have  to pre-authenticate before using your webservice:

WebService.webClass myWC= new WebService.webClass();

myWC.PreAuthenticate = true;

myWC.Credentials = System.Net.CredentialCache.DefaultCredentials;

posted on Friday, January 30, 2004 8:37 AM

Feedback

# re: The request failed with HTTP status 401: Unauthorized 2/19/2004 7:49 AM John Watson

Thanks for this, saved me a lot of head banging! - couldnt find anything that worked with why my webservice wouldnt work over my intranet!

# re: The request failed with HTTP status 401: Unauthorized 5/6/2004 9:53 AM Ron Zhang

Thanks for the help, it worked for me!

# re: The request failed with HTTP status 401: Unauthorized 7/2/2004 12:07 PM Dhanesh Shah

Thanks a lot. This saved a lot of trouble debugging!!

# re: The request failed with HTTP status 401: Unauthorized 9/22/2004 8:33 AM Matt

Are you logged onto the domain when this happens?

# re: The request failed with HTTP status 401: Unauthorized 9/22/2004 8:35 AM zee

Yes I am logged onto the domain.

# re: The request failed with HTTP status 401: Unauthorized 10/18/2004 7:03 AM Nilesh

Hi,
I've the same problem. I can eliminated the problem by "Recalculate Server Extensions" on IIS. I found this on MSDN.

1. Open IIS Admin console, navigate to your virtual directory
2. Right click, from All Tasks menu item select "Recalculate Server Extensions"
3. It opens IE window, click on Recalculate Web button.


But this error keeps reappearing when I deploy any other application to server.

If any one has fixed this before pls let me know.

# re: The request failed with HTTP status 401: Unauthorized 11/1/2004 9:27 PM Shashi

I am passing credentials to web service..still I get the same error...What could be the probelm?

# re: The request failed with HTTP status 401: Unauthorized 11/2/2004 3:20 AM Matt

Are you sure that the account has access?

# re: The request failed with HTTP status 401: Unauthorized 5/31/2005 10:46 PM Sandy

Thank you, thank you! Bless you. I spent hours banging my head over this error.

# re: The request failed with HTTP status 401: Unauthorized 6/13/2005 12:12 AM Micha

I still get same error. Help...

# re: The request failed with HTTP status 401: Unauthorized 7/19/2005 12:14 AM Anacel

Thanks~ I finally got my web service working on deployemnt site also

# re: The request failed with HTTP status 401: Unauthorized 8/16/2005 11:56 AM Matt

I am getting the same error: 401 Unauthorized. Where do I insert your code? Am hosting the website on GoDaddy.com shared Windows server running ASP.NET. My Web application works great on my //localhost but gets the 401 error when I try running it from the remote server. Please help!

# re: The request failed with HTTP status 401: Unauthorized 8/16/2005 12:32 PM Matt

Before you call your web service?

# re: The request failed with HTTP status 401: Unauthorized 8/16/2005 12:51 PM Matt

Once the user submits the form that calls the MapPoint web service, the 401 error is displayed. The exact same application works fine at my //localhost, so my user/password are OK. Any ideas? I have deleloped this web app using Visual Studio .NET 2003.

# re: The request failed with HTTP status 401: Unauthorized 8/25/2005 1:37 PM Kathleen

I'm new to this. I created a webservice and it tested fine, but when I tried to "consume" it, I got the 401 error message. So, I have the same question, where do I insert the code? Also, do I copy the code verbatim?

# re: The request failed with HTTP status 401: Unauthorized 8/25/2005 5:19 PM Kathleen

OK, never mind...I finally got it! Besides being new, I'm using VB, so the above code confused me a bit. I just needed this one line of code (MyWebService.credentials = System.Net.CredentialCache.DefaultCredentials) before I made a call to the web method I was after. Where "MyWebService" is an instance of the class that was generated to represent the web reference I added to my web app. (I hope that made sense.)

# re: The request failed with HTTP status 401: Unauthorized 9/9/2005 12:24 PM Henry

I am having similiar problem and the problem is I get the same error message but I don't know where to put the credentials? I need to pass in a encrypted string to the web services to allow me access but I can't seemed to figure it out. Thanks.

# re: The request failed with HTTP status 401: Unauthorized 9/22/2005 5:23 AM Busa

Thanks for the ready solution.
It worked !!!!

For understanding, if I am not on the same domain how to resolve this problem.

# re: The request failed with HTTP status 401: Unauthorized 10/15/2005 9:59 AM Iza Soufi

Hi, I am having a similar problem
I used below code :
WebService.webClass myWC= new WebService.webClass();

myWC.PreAuthenticate = true;

myWC.Credentials = System.Net.CredentialCache.DefaultCredentials;

but not response!
plz help

# re: The request failed with HTTP status 401: Unauthorized 12/13/2005 12:37 PM Alexandre

Salve!
From Brasil! Thanks for your instruction.
Regards
Alexandre
allexz@viaoceanica.com.br

# re: The request failed with HTTP status 401: Unauthorized 1/15/2006 11:35 AM Nits

Im getting the same error..Can tou please tell me where to write the Preauthenticate code which you have given above

# re: The request failed with HTTP status 401: Unauthorized 1/15/2006 1:59 PM Matt

Place the preauthenticate code before your call to the method, after the webservice instance is instantiated.

# OMG.. Thats it.. 1/16/2006 5:19 AM Mehmet

At the end, I could solve the problem with this 2 lines codes after trying a lot of settings.
Thank you very much.

# re: The request failed with HTTP status 401: Unauthorized 1/16/2006 6:56 AM Ram

Terrific, saved lot of debug time.

Thanks a lot,
-Ram

# re: The request failed with HTTP status 401: Unauthorized 3/7/2006 10:52 AM Jack

Hi,

This works, except from inside a thread that I spawned... I get the same error there.

Any ideas? Thanks!

# re: The request failed with HTTP status 401: Unauthorized 6/29/2006 6:30 AM Soumya Mukherjee

Thanx for the solution..it really works..

# re: The request failed with HTTP status 401: Unauthorized 5/14/2007 6:23 AM auto insurance

Hello all

# re: The request failed with HTTP status 401: Unauthorized 5/25/2007 9:17 AM Google排名

Good ! thank the author.

# re: The request failed with HTTP status 401: Unauthorized 6/26/2007 3:19 AM Rahul Bagaria

Hey a lot of thanks to you fr solving my Problem! I was utterly frustrated onthis particular bug in my web service...

# re: The request failed with HTTP status 401: Unauthorized 7/9/2007 12:20 PM kyle

Thank you

# re: The request failed with HTTP status 401: Unauthorized 10/2/2007 2:30 PM Usb flashdrive

Interesting article!
Thanks

# re: The request failed with HTTP status 401: Unauthorized 10/15/2007 9:06 PM proxy site

..Hey a lot of thanks to you fr solving my Problem! I was utterly frustrated onthis particular bug in my web service......

# re: The request failed with HTTP status 401: Unauthorized 3/19/2008 1:58 PM Opony

Interesting article!
Thanks

# re: The request failed with HTTP status 401: Unauthorized 3/24/2008 7:49 AM Gry

Keep up the good work.

Title  
Name  
Url
Comments   
Protected by Clearscreen.SharpHIPEnter the code you see: