2014-07-18 3 views
1

cURL을 사용하여 REST API를 호출하고 있습니다. 그리고 아래의 코드는 GET 방식을 위해 작동하지만 내가 추가 한 후 호출 그러나 대한 POST 방법은 작동하지 않습니다cURL POST 메서드가 작동하지 않습니다.

 curl_setopt($ch, CURLOPT_POST, true); 

은 무엇 원인이 될 수 있을까?

$options = array(
       CURLOPT_RETURNTRANSFER => true,  // return web page 
       CURLOPT_HEADER   => false, // don't return headers 
       CURLOPT_FOLLOWLOCATION => true,  // follow redirects 
       CURLOPT_ENCODING  => "",  // handle all encodings 
       CURLOPT_USERAGENT  => "spider", // who am i 
       CURLOPT_AUTOREFERER => true,  // set referer on redirect 
       CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
       CURLOPT_TIMEOUT  => 120,  // timeout on response 
       CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 
       CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks 
       CURLOPT_HTTPHEADER  => array('appId: C579929D-F0AA-4A8F-B6C6-1FF96694483C','appKey: AE78E7F1-FBDE-45F5-BAC2-210CEE9D3ED9') 
       ); 

      $url = "some-url"; 
      $ch = curl_init($url); 
      curl_setopt_array($ch, $options); 
      curl_setopt($ch, CURLOPT_POST, true); 
      $output = curl_exec($ch); 
      echo $output; 

P.S 나는 우체부를 사용하여 API 호출을 확인하고 예상 된 결과를 반환 배

.

API 호출에 추가 속성을 추가해야합니까?

와 나는 형식의 REST API를 호출 할 필요가 :

https://api.abc.com/v1/transactions/companyid/123/userid/456/description/ppeck/‌​source/PPA 

그리고이 질문에 제안 나는 나의 코드를 업데이트 :

 $url = "https://api.abc.com/v1/transactions"; 
     $ch = curl_init($url); 
     curl_setopt_array($ch, $options); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, "companyid=12301&userid=31401&description=ppa-check&source=PPA&amount=123&txndate=010111&txntypeid=420&customerid=2701"); 
     $output = curl_exec($ch); 

그리고 슬프게도 그 일을하지 않았다.

+0

같은 (&)를 추가로 쿼리 문자열로해야 시도? –

+0

'$ https : // api.abc.com/v1/transactions/companyid/123/userid/456/description/ppeck/source/PPA '와 같이 $ url 필드에 추가 할 것입니다. – Runcorn

답변

2

는 후 필드

당신이 게시하는 어떤 분야
$url = 'http://example.com'; //your api call url 
    $fields = 'q=example&y=fgt&ghty'; // all posting fields separated with & 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
+0

작동하지 않았습니다. .. – Runcorn

+0

새로운 코드 –

+0

으로 질문 업데이트를 시도해보십시오. – Runcorn

관련 문제