401 when POSTing using HttpWebRequest (yes I used

2019-05-07 10:49发布

问题:

I'm using HttpWebRequest to pull down XML, and POST data back to a 'WebService' and getting a 401 on the POST.

When creating the requests I've added Credentials and now tried a credentials cache and setting PreAutenticate to True, still getting the 401! :(

Watching the HTTP traffic on the router I set the get make an unauthenticated GET request.. it hits the 401 and then makes an authenticated GET and is allowed through. When I watch the POST I see it hit the 401... and it doesn't even try an authenticated POST.

This appears only on mobile phones (compact-framework 3.5 and 2.0 on WinMobile 6.1). The same .exe works perfectly on any desktop machines.

What am I missing? Please help!

回答1:

Try setting the header manually:

http://devproj20.blogspot.com/2008/02/assigning-basic-authorization-http.html