2017-04-19 3 views
0

Ich benutze curl reques, um einen Bericht von SMS zu erhalten, aber einige Probleme zu begegnen. Ich habe auch durch Codierung URL verschlüsselt, aber immer noch das gleiche Problem. 400 ungültige Anfrage wird angezeigt.HTTP-Fehler 400. Die Anfrage ist schlecht gebildet. on curl request

$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 

} 

Antwort

0

Dies passiert, wenn Sie Whitespaces in URL haben. Du musst der URL entkommen. Folgen Sie dem untenstehenden Code

<?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 

     } 

Danach wird eine ungültige Inhaltslänge angezeigt. Entfernen Sie die Kommentarzeichen für die Zeile CURLOPT_POSTFIELDS, und übergeben Sie die richtigen Anmeldeinformationen. Definitiv wird es funktionieren.

+0

Dank Devinder Kumar, ich habe meinen Code geändert, wie Sie gesagt haben, aber jetzt gibt es diesen Fehler. "Serverfehler in '/' Anwendung." –

+0

Bitte beziehen Sie sich darauf. http://stackoverflow.com/questions/28888267/server-error-in-application-when-attempting-to-curl#answer-28907180 –

Verwandte Themen