php-curl使用代理时不正确的标头大小 [英] php-curl incorrect header size when use proxy

查看:235
本文介绍了php-curl使用代理时不正确的标头大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码:

$headersSize     = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($response, 0, $headersSize);
$responseBody    = substr($response, $headersSize);

返回标头大小(strlen)不正确。这里:

return incorrect size (strlen) of headers, e.g. here:

...
Pragma: no-cache
Set-Cookie: foo=bar; pat

 ---- curl want split here ---- 

h=/
Access-Control-Allow-Origin: *

<!DOCTYPE html ...

响应可以有多个标头(重定向,继续等。)。和这样的类似这样的工作:

Response can have multiple headers (redirections, continue, etc.). And ofcourse like this isnt work:

list($header, $body) = explode("\r\n\r\n", $response, 2);

如何更正标头大小?

推荐答案

可能与此相关: https://bugs.php.net/bug.php?id=63894&edit=1 http://sourceforge.net/p/curl/bugs/1204


修复是commit bc6037e它进入卷曲7.30.0

That fix was commit bc6037e which went into curl 7.30.0

无论如何,这是一个错误。任何修复此错误后将不可靠。

Anyway, it's a bug. Any fix after this bug will be unreliable.

知道它是如何工作的,你可以手动添加/减去标题的长度一个特定的金额,只是看看它有多少。

Knowing how it works, you can just manually add/subtract to the length of the header by a specific amount, just see how much it's missing.

或者如果代理仅用于HTML,那么您可以手动解析字符串,直到获得以HTML标记开头的行,即标题结束的位置。

Or if the proxy is used only for HTML, then you can manually parse the string until you get a line that starts with a HTML tag, which is where your header ends.

对不起,但我没有看到一个可靠的解决方案,而不是从源头修复这个错误。如果可以,你可以更新curl,libcurl或任何。或者你可以从git拉取版本,修复这个错误,重新编译,如果你是版本敏感的。

Sorry, but I don't see a reliable solution other than to fix this bug at the source. If you can, you can just update curl, libcurl or whatever. Or you can pull that version from git, fix this bug, recompile, if you're version-sensible.

这篇关于php-curl使用代理时不正确的标头大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆