2017-04-19 15 views
0

私は、SMSの報告を得るためにいくつかの問題に直面するためにcurlの要求を使用しています。私もURLをエンコードすることによってckeckedているが、同じ問題がまだあります。 400の不正なリクエストが表示されています。HTTPエラー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 

} 

答えて

0

これは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行のコメントを外し、正しい資格情報を渡します。確かにそれは動作します。

+0

ありがとうDevinder Kumar、あなたが言ったように私のコードを変更しましたが、今はこのエラーを出しています。 "'/'アプリケーションのサーバーエラー。" –

+0

これを参照してください。 http://stackoverflow.com/questions/28888267/server-error-in-application-when-attempting-to-curl#answer-28907180 –

関連する問題