|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-10-05 12:22 UTC] j dot wessel at nolis dot de
Description:
------------
Tested with: PHP 7.1.10, PHP 5.6.31 and curl 7.56.0
The script works with curl 7.55.0 correctly.
Test script:
---------------
curl.php
--------------------------------------------------------------------------------------
<?php
//generate string data
function getStr($num) {
$bstring = 'abcdefghijklmnopqrstuvxyz0123456789';
$str = '';
for($i = 0; $i < $num; $i++) {
$str .= $bstring;
}
return $str;
}
$json = [
'json1' => getStr(200),
'json2' => getStr(200),
'json3' => getStr(200),
'json4' => getStr(200),
];
$post = [
'test1' => 'a',
'test2' => 'b',
'test3' => 'c',
'test4' => json_encode($json) //or use print_r or var_dump with return parameter
];
$ch = curl_init();
//send encoded json-data to service
curl_setopt($ch, CURLOPT_URL, 'https://localhost/service.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
curl_close($ch);
var_dump($result);
?>
service.php
--------------------------------------------------------------------------------------
<?php
//get the post data and write into request.log
$result = file_put_contents('request.log', print_r($_REQUEST, true));
var_dump($result);
//the content of $_REQUEST is wrong, json1 is repeated, content is cutted off
//expected result: correct content in $_REQUEST
?>
Expected result:
----------------
Correct post data in $_REQUEST.
Actual result:
--------------
the content of $_REQUEST is wrong, json1 is repeated, content is cutted off, the post data is corrupt
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 17:00:01 2025 UTC |
PHP 5.4.45 and curl 7.56.0 2 scripts: 1. test.php ---------------------------- <?php //get the post and return it back var_dump($_POST); ?> ------------------------------ 2. test2.php ------------------------------------------- <?php $string="There is some random human-readable data number "; $arr=[]; for($i=0;$i<1000;$i++) { $arr[$i]=$string.$i; }; $toSend=(['short_data_test'=>"123",'long_json'=>json_encode($arr),'something_else'=>'333222111']); $curl= curl_init(); $options = [ CURLOPT_URL => "http://localhost/test.php", CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $toSend ]; curl_setopt_array($curl, $options); $result=curl_exec($curl); curl_close($curl); echo"<pre>".PHP_EOL; echo "we send:<br/>".PHP_EOL; echo var_dump($toSend)."<br/>".PHP_EOL; echo "<br/>"; echo "remote side got:<br/>".PHP_EOL; echo $result."<br/>".PHP_EOL; echo "<br/>"; echo "</pre>"; ?> -------------------------------------------------------------------------- now, execute taht script, and see: (part of json) "There is some random human-readable data number 300","There is some random human-readable["There is some random human-readable data number 0" and that repeats so and so on - every 16384 symbols of long sting (16k).