401 Error on POST using DefaultCredentials

B

Bfranknyc

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top