Heim  >  Artikel  >  php教程  >  RCA:未注意Curl-library Post 1024以上字节时的HTTP/1.1特性导致 HessianPHP 传

RCA:未注意Curl-library Post 1024以上字节时的HTTP/1.1特性导致 HessianPHP 传

WBOY
WBOYOriginal
2016-06-13 11:31:441496Durchsuche

先列出 HessianPHP 的错误提示:


基础知识背景: 1)“Expect: 100-continue”的来龙去脉:     HTTP/1.1 协议里设计 100 (Continue) HTTP 状态码的的目的是,在客户端发送 Request Message 之前,HTTP/1.1 协议允许客户端先判定服务器是否愿意接受客户端发来的消息主体(基于 Request Headers)。     即,Client 和 Server 在 Post (较大)数据之前,允许双方“握手”,如果匹配上了,Client 才开始发送(较大)数据。     这么做的原因是,如果客户端直接发送请求数据,但是服务器又将该请求拒绝的话,这种行为将带来很大的资源开销。       协议对 HTTP/1.1 clients 的要求是:
 的头域!  
2)libcurl 发送大于1024字节数据时启用“Expect:100-continue‘特性:

1. 发送一个请求,包含一个 "Expect: 100-continue" 头域,询问 Server 是否愿意接收数据; 2. 接收到 Server 返回的 100-continue 应答以后,才把数据 POST 给 Server;

 

    zxgfa 在 2012年补充说:

(郑昀注1:lighttpd 1.4 版本有此严重问题,于1.5版本修复。 郑昀注2:Resin 于 3.0.5 版本增加了对 Expect: 100-continue 的支持。)

 

3)PHP Curl-library 可以主动封禁此特性:     有人在 PHP手册::curl_setopt 下留言说:     PHP curl 遵从 libcurl 的特性。由于不是所有 web servers 都支持这个特性,所以会产生各种各样的错误。如果你遇到了,可以用下面的命令封禁"Expect"头域:     <span class="html"><span class="default">    <?php </span></span></span> <span class="html"><span class="default">    curl_setopt</span><span class="keyword">(</span><span class="default">$ch</span><span class="keyword">,<span class="Apple-converted-space"> </span></span><span class="default">CURLOPT_HTTPHEADER</span><span class="keyword">, array(</span><span class="string">'Expect:'</span><span class="keyword">));<br></span><span class="default">    ?><br></span><span pooy><br></span></span>         图1 You can convince PHP's curl backend to stop doing the 100-continue-thing by setting an explicit request header  
其他知识背景:
  • 根据 HessianTransport 代码所述,”Hessian request using the CURL library“。

问题现象:
,hessian 报错“CURL transport error: transfer closed with outstanding read data remaining”。
  解决: 修改hessian中 CURLOPT 项: CURLOPT_HTTPHEADER => array("Content-Type: application/binary")  改为 CURLOPT_HTTPHEADER => array("Content-Type: application/binary","Expect:") 
p.s.:     有人认为改为 HTTP/1.0 协议即可绕过这个 100-continue 问题,但这只是工程师不愿意搞清楚原理而示弱的表现。   参考资源: 1)2011,Laruence,Expect:100-continue; 2)PHP手册,If you are doing a POST, and the content length is 1,025 or greater; 3)HTTP 1.1 RFC,Use of the 100 (Continue) Status; 4)stackoverflow,2009,PHP HTTP POST fails when cURL data > 1024; 5)zxgfa,2012,libcurl的使用问题“Expect100-continue”; 6)lighttpd,2009,'Expect' header gives HTTP error 417;
赠图几枚: 请施主拿去: 360度后空翻开球: 360无死角:  

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn