Php HTTP错误400。请求的格式不正确。应客户要求

Php HTTP错误400。请求的格式不正确。应客户要求,php,curl,laravel-5.2,Php,Curl,Laravel 5.2,我正在使用curl请求获取sms报告,但面临一些问题。我也检查了编码的网址,但仍然是相同的问题。 显示400个错误请求 $url="http://api.smscountry.com/smscwebservices_bulk_reports.aspx?user=&passwd=&fromdate=19/04/2017 00:00:00&todate=19/04/2017 23:59:59&jobno=60210892"; //callbackURL=http:/

我正在使用curl请求获取sms报告,但面临一些问题。我也检查了编码的网址,但仍然是相同的问题。 显示400个错误请求

$url="http://api.smscountry.com/smscwebservices_bulk_reports.aspx?user=&passwd=&fromdate=19/04/2017 00:00:00&todate=19/04/2017 23:59:59&jobno=60210892";  //callbackURL=http://www.jouple.com/marketing/public/save/sms
$ch = curl_init();
if (!$ch){
    die("Couldn't initialize a cURL handle");
}
$ret = curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt ($ch, CURLOPT_POSTFIELDS,
// "User=$user&passwd=$password&sid=$senderid");
// $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//If you are behind proxy then please uncomment below line and provide your proxy ip with port.
// $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");
$curlresponse = curl_exec($ch); // execute

// print_r($ch);die;
if(curl_errno($ch))
    echo 'curl error : '. curl_error($ch);
if (empty($ret)) {
// some kind of an error happened
    die(curl_error($ch));
    curl_close($ch); // close cURL handler
} else {
    $info = curl_getinfo($ch);
    curl_close($ch); // close cURL handler

}

当URL中有空格时会发生这种情况。您必须转义url。遵循下面的代码

<?php
$url="http://api.smscountry.com/smscwebservices_bulk_reports.aspx/";  //callbackURL=http://www.jouple.com/marketing/public/save/sms
$url2= "?user=&passwd=&fromdate=19/04/2017 00:00:00&todate=19/04/2017 23:59:59&jobno=60210892";
        $ch = curl_init();
        $url = $url . curl_escape($ch, $url2);
        if (!$ch){
            die("Couldn't initialize a cURL handle");
        }
        $ret = curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        // curl_setopt ($ch, CURLOPT_POSTFIELDS,
        // "User=$user&passwd=$password&sid=$senderid");
        // $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        //If you are behind proxy then please uncomment below line and provide your proxy ip with port.
        // $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");
        $curlresponse = curl_exec($ch); // execute

        // print_r($ch);die;
        if(curl_errno($ch))
            echo 'curl error : '. curl_error($ch);
        if (empty($ret)) {
        // some kind of an error happened
            die(curl_error($ch));
            curl_close($ch); // close cURL handler
        } else {
            $info = curl_getinfo($ch);
            curl_close($ch); // close cURL handler

        }

在此之后,您将面临无效内容长度错误。取消对行CURLOPT_POSTFIELDS的注释,并传递正确的凭据。肯定能用。

谢谢Devinder Kumar,我已经按照你说的更改了代码,但现在它给出了这个错误。“/”应用程序中出现服务器错误。请参阅此。