Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > 401 Error on POST using DefaultCredentials

Reply
Thread Tools

401 Error on POST using DefaultCredentials

 
 
Bfranknyc
Guest
Posts: n/a
 
      11-21-2008
Seeing strange behavior when accessing a web service (Microsoft MVC) on IIS
7. My client has a library with a generic HTTP submitter routine in it. I am
using integrated authentication and passing:

request.Credentials = CredentialCache.DefaultCredentials;

When I send a GET, my web service is able to authenticate and all is good.
When I send a POST, my web service returns a 401.

Here is the GET code:
Uri uri = new Uri(url + "?" + httpData);
request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultCredentials;
request.KeepAlive = true;
request.Timeout = 5000;
WebResponse webResponse = request.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(responseStream);
String responseString = responseReader.ReadToEnd();
webResponse.Close();

Here is the PUT code:
Uri uri = new Uri(url);
request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = httpData.Length;
using (Stream writeStream = request.GetRequestStream())
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(httpData);
writeStream.Write(bytes, 0, bytes.Length);
}
WebResponse webResponse = request.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(responseStream);
String responseString = responseReader.ReadToEnd();
webResponse.Close();


Webserver log line for GET:
2008-11-21 19:08:07 10.99.12.89 GET /users - 80 EMWP\bfranklin 10.100.30.69
- 200 0 0 46

Webserver log line for POST:
2008-11-21 18:28:29 10.99.12.89 POST /documents/upload/2008/1/01409/EMWP-811
- 80 - 10.100.30.67 - 401 2 5 0

Looks like credentials aren't being passed on a POST, any ideas? BTW the
posts work fine if I do it from a browser. Thanks in advance!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
401 Unauthorized on HttpWebRequest with DefaultCredentials (2003) ivarley@spamcop.net ASP .Net Security 1 03-31-2006 04:16 PM
Problem with authentication using DefaultCredentials elora_c@yahoo.com ASP .Net Security 5 11-15-2005 02:58 PM
Problem with authentication using DefaultCredentials elora_c@yahoo.com ASP .Net Web Services 5 11-15-2005 02:58 PM
POST data with 401 authentication using urllib(2) Pieter Edelman Python 0 03-25-2005 09:39 AM
401 Unauthorized when using DefaultCredentials Rodrigo Estrada ASP .Net Security 1 05-11-2004 12:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57