views:

185

answers:

2

I am connecting to a service using a HttpWebRequest. In the service logs, there are Authentication errors being logged, even though the information is correct. The vendor who set up the server with the service, has said that .NET does not send the authentication headers on the first try.

_Req.Credentials = new NetworkCredential(username, password);

When the request is sent, the server responds with needing the headers, which the request then sends. Is this correct, and is there a way to send it on the initial request?

A: 
HttpWebRequest request;
request.PreAuthenticate = true;
mickyjtwin
PreAuthenticate causes the headers to be sent on every request except the first. From MSDN: "With the exception of the first request, the PreAuthenticate property indicates whether to send authentication information with subsequent requests "
Rory MacLeod
A: 

See this question pointing to the answer in this article: add headers manually (even the first time).