nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 299 forks source link

Problem with NTLM Processing #200

Open tivotyro opened 9 years ago

tivotyro commented 9 years ago
Problem with NTLM Processing

I am trying to use your library to authenticate to a server - which just happens to be a Microsoft Lync server - via HTTPS and i can't get past an "HTTP Error 411. The request must be chunked or have a content length."

I am aware of #184 which resulted in a error 411, but there is not anything that I can see there that will help in my case.

composer.json
"nategood/httpful": "master"
code snippet
$response = Httpful\Request::post($this->user_base_url."/WebTicket/oauthtoken")
     ->contentType("application/x-www-form-urlencoded")
     ->body("grant_type=urn:microsoft.rtc:windows")
     ->ntlmAuth("my_username_here", "my_password_here")
     ->send(); 

print_r($response);
output
Httpful\Response Object
(
    [body] => <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

    [raw_body] => <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

    [headers] => Httpful\Response\Headers Object
        (
            [headers:Httpful\Response\Headers:private] => Array
                (
                    [content-type] => text/html; charset=us-ascii
                    [server] => Microsoft-HTTPAPI/2.0
                    [date] => Wed, 02 Sep 2015 18:41:18 GMT
                    [connection] => close
                    [content-length] => 344
                    [set-cookie] => MS-WSMAN=88082955.23313.0000; path=/
                )

        )

    [raw_headers] => HTTP/1.1 411 Length Required
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 02 Sep 2015 18:41:18 GMT
Connection: close
Content-Length: 344
Set-Cookie: MS-WSMAN=88082955.23313.0000; path=/
    [request] => Httpful\Request Object
        (
            [uri] => https://blah.blah.com/WebTicket/oauthtoken
            [method] => POST
            [headers] => Array
                (
                    [Content-Length] => 36
                )

            [raw_headers] => POST /WebTicket/oauthtoken HTTP/1.1
Host: blah.blah.com
Expect:
User-Agent: Httpful/0.2.19 (cURL/7.42.1 PHP/5.6.12 (WINNT))
Content-Type: application/x-www-form-urlencoded
Accept: */*; q=0.5, text/plain; q=0.8, text/html;level=3;
Content-Length: 36

            [strict_ssl] => 
            [content_type] => application/x-www-form-urlencoded
            [expected_type] => 
            [additional_curl_opts] => Array
                (
                    [107] => 8
                )

            [auto_parse] => 1
            [serialize_payload_method] => 2
            [username] => my_username_here
            [password] => my_password_here
            [serialized_payload] => grant_type=urn:microsoft.rtc:windows
            [payload] => grant_type=urn:microsoft.rtc:windows
            [parse_callback] => 
            [error_callback] => 
            [send_callback] => 
            [follow_redirects] => 
            [max_redirects] => 25
            [payload_serializers] => Array
                (
                )

            [_ch] => Resource id #31
            [_debug] => 
        )

    [code] => 411
    [content_type] => text/html
    [parent_type] => text/html
    [charset] => us-ascii
    [meta_data] => Array
        (
            [url] => https://blah.blah.com/WebTicket/oauthtoken
            [content_type] => text/html; charset=us-ascii
            [http_code] => 411
            [header_size] => 233
            [request_size] => 326
            [filetime] => -1
            [ssl_verify_result] => 19
            [redirect_count] => 0
            [total_time] => 0.468
            [namelookup_time] => 0
            [connect_time] => 0.063
            [pretransfer_time] => 0.187
            [size_upload] => 0
            [size_download] => 344
            [speed_download] => 735
            [speed_upload] => 0
            [download_content_length] => 344
            [upload_content_length] => 0
            [starttransfer_time] => 0.468
            [redirect_time] => 0
            [redirect_url] => 
            [primary_ip] => *VALID_IP_WAS_HERE*
            [certinfo] => Array
                (
                )

            [primary_port] => 443
            [local_ip] => *VALID_IP_WAS_HERE*
            [local_port] => 51436
        )

    [is_mime_vendor_specific] => 
    [is_mime_personal] => 
    [parsers:Httpful\Response:private] => 
)
tivotyro commented 9 years ago

Coincidentally, I can run the following curl command with success:

curl -X POST -d "grant_type=urn:microsoft.rtc:windows" -u my_username_here:my_password_here --anyauth https://blah.blah.com/WebTicket/oauthtoken

{
    "access_token":"cwt=AAEBHAEFAAAAAAAFFQAAAD-tFGK0e3M0dbl1VIX4BwCBEMYh8glV_kVdpAIyQn_jhRyCAv6RgyA6WQMLr1sf_ajMNOasRS9IPnRbyiIQLICS1nzHJG6BD4YIT3dWsQC00ggNECrAWnUloP9ZsB_JoTj_B7k",
    "expires_in":27802,
    "ms_rtc_identityscope":"local",
    "token_type":"Bearer"
}
cherouvim commented 7 years ago

Any luck with this one? I confirm it's an issue.

A workaround is to do:

->addHeader('Transfer-Encoding', 'chunked')