PUT with basic authentication

Topics: Web Api
Dec 7, 2010 at 9:18 PM

I am having problems doing a PUT operation on a web service which requires basic authentication. The HttpClient doesn't try to send the Authorization header when the server returns with HTTP error 401.

My code is like this:

HttpClient http = new HttpClient(USER_URL);
http.TransportSettings.Credentials = new NetworkCredential(tbUsername.Text, tbPassword.Text);
//.. content created
resp = http.Put(REL_URL, content);

If I try to do a GET with the same code, HttpClient will call the server twice - once without credentials, and then when the server returns 401, it will perform the request again with the Authorization header.

How can I make PUT try to authenticate?