在cUrl中获取400个错误请求 - PHP

时间:2017-02-15 18:14:47

标签: php curl

我正在运行以下代码并收到此错误:

  

错误请求

     

您的浏览器发送了此服务器无法理解的请求。

     

此外,尝试时遇到了400 Bad Request错误   使用ErrorDocument来处理请求。

    <?php
      $phone = "1236547895";
      $message = 'Dear '.$firstname.' '.$lastname.',

Your invoice (#'.$invoiceid.') is successfully paid on '.$datepaid.' at Hostomy. Thank you for choosing us.

Regards,
Hostomy
';
      $url = "https://www.example.com/file.php?phone=".$phone."&message=".$message."";
      $ch = curl_init();
      $timeout = 10;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
    ?>

1 个答案:

答案 0 :(得分:6)

尝试urlencode消息和$ phone vars:
$url = "https://www.example.com/file.php?phone=".urlencode($phone)."&message=".urlencode($message)."";