0

Whenever a web request is made by Visual Studio to TFS, Fiddler will show a 401 Unauthorized error. Visual Studio will then try again with a proper Authorization Negotiate header in place with which TFS will respond with the proper data and a 200 status code.

How can I get the correct headers to be sent the first time to stop the 401?

Ray Booysen
  • 28,894
  • 13
  • 84
  • 111

3 Answers3

5

This is how the process of Windows Integrated Authentication (NTLM) works. NTLM is a connection based authentication mechanism and actually involves 3 calls to establish the authenticated session.

The TFS API then goes to extra-ordinary lengths to make sure that this handshake is done in the most efficient way possible. It will keep the authenticated connection open for a period of time to avoid this hand-shake where possible. It will also do the initial authentication using a HTTP payload with minimal content and then send the real message if the message you were going to send is over a certain length. It does a bunch of other tricks as well to optimise the connection to TFS.

Basically, I would just leave it alone as it works well.

Martin Woodward
  • 11,770
  • 31
  • 45
0

This is how it's always done - request, get the 401 back, then send the authorization. It's part of the authentication protocol for http.

Brady Moritz
  • 8,624
  • 8
  • 66
  • 100
0

You will see that a web browser also does this when communicating with a web site. It will always try to give away the minimum amount of detail with the first call. If this fails, it will reveal a little more about you.

This is by design and for a very good reason.

Chris Simpson
  • 7,821
  • 10
  • 48
  • 68