2016-02-03 464 views
1

我使用支持http2.0協議安裝curl,並且我在版本信息中看到HTTP2。無法發送curl的HTTP/2請求

$ ./curl --version 
curl 7.42.1 (x86_64-apple-darwin14.5.0) libcurl/7.42.1 OpenSSL/1.0.2a zlib/1.2.5 nghttp2/0.7.13 
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 

但是,當我通過curl發送請求(詳細模式),我看到http1.1協議。

./curl -v --http2 https://http2bin.org/get 
* Trying 104.131.161.90... 
* Connected to http2bin.org (104.131.161.90) port 443 (#0) 
* ALPN, offering h2-14 
* ALPN, offering http/1.1 
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH 
* successfully set certificate verify locations: 
* CAfile: /usr/local/etc/openssl/cert.pem 
    CApath: none 
* TLSv1.2, TLS Unknown, Unknown (22): 
* TLSv1.2, TLS handshake, Client hello (1): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, Server hello (2): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, CERT (11): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, Server key exchange (12): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, Server finished (14): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, Client key exchange (16): 
* SSLv2, Unknown (20): 
* TLSv1.2, TLS change cipher, Client hello (1): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, Finished (20): 
* SSLv2, Unknown (20): 
* TLSv1.2, TLS change cipher, Client hello (1): 
* SSLv2, Unknown (22): 
* TLSv1.2, TLS handshake, Finished (20): 
* SSL connection using TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384 
* ALPN, server accepted to use h2-14 
* Server certificate: 
* subject: OU=Domain Control Validated; OU=EssentialSSL; CN=www.http2bin.org 
* start date: 2015-02-21 00:00:00 GMT 
* expire date: 2016-02-21 23:59:59 GMT 
* subjectAltName: http2bin.org matched 
* issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA 
* SSL certificate verify ok. 
* Using HTTP2 
* Using HTTP2 
* SSLv2, Unknown (23): 
* SSLv2, Unknown (23): 
* SSLv2, Unknown (23): 
> GET /get HTTP/1.1 
> Host: http2bin.org 
> User-Agent: curl/7.42.1 
> Accept: */* 
> 
* http2_recv: 16384 bytes buffer 
* SSLv2, Unknown (23): 
* SSLv2, Unknown (23): 
* http2_recv: 16384 bytes buffer 
* SSLv2, Unknown (23): 
* http2_recv: 16384 bytes buffer 
* SSLv2, Unknown (23): 
< HTTP/2.0 200 
< server:h2o/1.6.1 
< date:Wed, 03 Feb 2016 15:44:23 GMT 
< content-type:application/json 
< access-control-allow-origin:* 
< access-control-allow-credentials:true 
< x-clacks-overhead:GNU Terry Pratchett 
< content-length:252 
< 
{ 
    "args": {}, 
    "headers": { 
    "Accept": "*/*", 
    "Connection": "keep-alive", 
    "Host": "http2bin.org", 
    "User-Agent": "curl/7.42.1", 
    "Via": "2 http2bin.org" 
    }, 
    "origin": "193.238.96.12", 
    "url": "https://http2bin.org/get" 
} 
* Connection #0 to host http2bin.org left intact 

現在捲曲發送請求經由HTTP/1.1

如果我設置--http1.0選項,然後捲曲發送經由HTTP/1.0的請求。

爲什麼cURL不通過HTTP/2.0發送請求?

操作系統:OS X Yosemite(10.10.5)。

通過HomeBrew安裝cURL和OpenSSL。

謝謝。

回答

4

它實際上已經發送和接收HTTP/2(draft-14版本,這是規範的預發佈版本)。你應該考慮升級你的curl和nghttp2庫,讓它說出最終版本的HTTP/2協議(RFC 7540)。從服務器

提示:

* ALPN, server accepted to use h2-14 

捲曲示出了使用HTTP/1式,使它看起來熟悉,但其轉換引擎蓋下它HTTP/2,並將其發送關閉請求。

服務器然後用HTTP/2響應:

< HTTP/2.0 200 
< server:h2o/1.6.1 
< date:Wed, 03 Feb 2016 15:44:23 GMT 
< content-type:application/json 
< access-control-allow-origin:* 
[snip] 
+1

謝謝,我不知道,什麼嫋嫋只顯示HTTP/1.1請求,併發送之前被轉換爲2.0。 – ZhukV