使用curl geting发送post请求404

uhry853o  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(183)

zendserver 2019.7 php 7.3 apache 2.4版本的开发工具
在测试环境中,我通过curl发送JSON post请求到我的本地服务器。当CURLOPT_POSTFIELDS少于1000个字符时,它的脚本就被执行了,我得到的响应很好。
但是,当我增加JSON数组的长度时,同一个脚本会出现404错误。
我已经改变了所有的配置,如后_最大_大小等,但没有工作。

$json_data = '{
  "Recon": [
      {
          "ItemNumber": "96",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "97",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "98",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "99",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "100",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "101",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "102",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "103",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "104",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "105",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "106",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "107",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      },
      {
          "ItemNumber": "108",
          "StorageLocation": "L1",
          "Quantity": "2060.800",
          "UOM": "KG"
      }
  ]
}';

$url = 'http://ipaddress/projectname/recon.php';

$ch = curl_init($url);curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$result = curl_exec($ch);

curl_close($ch);
echo $result;
hgncfbus

hgncfbus1#

curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);您尝试发送字符串。
php手册说:
弯折_后置字段
要在HTTP“POST”操作中发送的完整数据。此参数可以作为URL编码字符串(如'para1=val1&para2=val2&...')传递,也可以作为数组(以字段名作为键,以字段数据作为值)传递。
尝试以下操作,将字符串转换为数组,其中键名为myjson:
curl_setopt($ch, CURLOPT_POSTFIELDS, ['myjson'=>$json_data]);

相关问题