php curl 1024,当cURL数据> 1024时,PHP HTTP POST失败

注意:最后的解决方案

如果我尝试执行超过1024个字符的HTTP POST,则会失败.为什么?这是一个最小的例子:

recipient.php:

if (strlen(file_get_contents('php://input')) > 1000

|| strlen($HTTP_RAW_POST_DATA) > 1000) {

echo "This was a triumph.";

}

?>

sender.php:

function try_to_post($char_count) {

$url = 'http://gpx3quaa.joyent.us/test/recipient.php';

$post_data = str_repeat('x', $char_count);

$c = curl_init();

curl_setopt_array($c,

array( CURLOPT_URL => $url,

CURLOPT_HEADER => false,

CURLOPT_CONNECTTIMEOUT => 999,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_POST => 1,

CURLOPT_POSTFIELDS => $post_data

)

);

$result = curl_exec($c);

echo "{$result}\n";

curl_close($c);

}

for ($i=1020;$i<1030;$i++) {

echo "Trying {$i} - ";

try_to_post($i);

}

?>

输出:

Trying 1020 - This was a triumph.

Trying 1021 - This was a triumph.

Trying 1022 - This was a triumph.

Trying 1023 - This was a triumph.

Trying 1024 - This was a triumph.

Trying 1025 -

Trying 1026 -

Trying 1027 -

Trying 1028 -

Trying 1029 -

组态:

PHP Version 5.2.6

libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8

lighttpd-1.4.19

为cURL添加以下选项:

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

原因似乎是任何超过1024个字符的POST都会导致发送"Expect:100-continue"HTTP标头,而Lighttpd 1.4.*不支持它.我找到了一张票:http://redmine.lighttpd.net/issues/show/1017

他们说它适用于1.5.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值