Heim  >  Artikel  >  Backend-Entwicklung  >  php使用curl出现Expect:100-continue解决方法_php技巧

php使用curl出现Expect:100-continue解决方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:22:081351Durchsuche

本文实例讲述了php使用curl出现Expect:100-continue解决方法。分享给大家供大家参考。具体如下:

使用curl POST数据时,如果POST的数据大于1024字节,curl并不会直接就发起POST请求。而是会分两步。

1.发送一个请求,header中包含一个Expect:100-continue,询问Server是否愿意接受数据。
2.接受到Server返回的100-continue回应后,才把数据POST到Server。

这个是libcurl定义的,具体可以查看相关描述:http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3

于是这样就会出现一个问题。并不是所有的Server都会回应100-continue的。例如lighttpd,会返回"417 Expectation Fail",会造成逻辑错误。

解决方法如下,就是发送请求时,header中包含一个空的Expect。

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:")); 

希望本文所述对大家的php程序设计有所帮助。

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