2017-04-19 2 views
0

curl reques를 사용하여 sms에 대한 보고서를 얻지 만 몇 가지 문제가 있습니다. 나는 또한 URL을 인코딩하여 ckecked했지만 여전히 같은 문제. 400 개의 잘못된 요청이 표시됩니다.HTTP 오류 400입니다. 요청이 잘못되었습니다. curl 요청시

$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

Thanks Devinder Kumar, 내가 말한대로 코드를 변경했지만 지금은이 오류를 제공합니다. " '/'응용 프로그램의 서버 오류." –

+0

이 부분을 참조하십시오. http://stackoverflow.com/questions/28888267/server-error-in-application-when-attempting-to-curl#answer-28907180 –