title: curl stops negotiating SPNEGO - unknown mech-code 0 for mech unknown
body: <p>I try to connect to an SPNEGO secured web site with curl (on Mac OS X 10.10 with shipped curl)</p>
  
  <pre>
  $curl -vv --negotiate -u : http://xxx-MacBook-Pro.local:8080 
  * Rebuilt URL to: http://xxx-MacBook-Pro.local:8080/
  *   Trying 192.168.1.6...
  * Connected to xxx-MacBook-Pro.local (192.168.1.6) port 8080 (#0)
  &gt; GET / HTTP/1.1
  &gt; Host: xxx-MacBook-Pro.local:8080
  &gt; User-Agent: curl/7.43.0
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 401 Unauthorized
  * gss_init_sec_context() failed: : unknown mech-code 0 for mech unknown
  &lt; WWW-Authenticate: Negotiate
  &lt; Content-Type: application/json; charset=UTF-8
  &lt; Content-Length: 303
  &lt; 
  * Connection #0 to host xxx-MacBook-Pro.local left intact
  </pre>
  
  <p>Problem seems to be "gss_init_sec_context() failed: : unknown mech-code 0 for mech unknown". curl looks like to be compiled with SPNEGO/GSS correctly?</p>
  
  <pre><code>curl 7.43.0 (x86_64-apple-darwin14.0) libcurl/7.43.0 SecureTransport zlib/1.2.5
  Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps     pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
  Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets 
  </code></pre>
  
  <p>EDIT: HTTPie (<a href="https://github.com/ndzou/httpie-negotiate" rel="nofollow">https://github.com/ndzou/httpie-negotiate</a>) shows similar behaviour. It stops after the first server response. <strong>Does it matter that the server return content with the 401 response and not just headers?</strong></p>
  
  <pre>
  GET / HTTP/1.1
  Accept: */*
  Accept-Encoding: gzip, deflate
  Connection: keep-alive
  Host: 192.168.1.6:8080
  User-Agent: HTTPie/0.9.2
  
  
  
  HTTP/1.1 401 Unauthorized
  Content-Length: 209
  Content-Type: application/json; charset=UTF-8
  WWW-Authenticate: Negotiate
  
  {
      "error": {
          "header": {
              "WWW-Authenticate": "Negotiate"
          }, 
          "reason": null, 
          "root_cause": [
              {
                  "header": {
                      "WWW-Authenticate": "Negotiate"
                  }, 
                  "reason": null, 
                  "type": "xxx"
              }
          ], 
          "type": "xxx"
      }, 
      "status": 401
  }
  </pre>
  
  <p>How can i make curl to get work and to use the correct mech? </p>