2016-07-19 2 views
1

URL에 대한 전화를 걸어야하는 API를 개발 중입니다.PHP가 json 요청을 보내고 있습니다.

몸은 나를 찾을 appears.Help 내가 스크립트 빈 페이지를 실행하면

{ 
"image":"http://media.kairos.com/kairos-elizabeth.jpg", 
"subject_id":"subtest1", 
"gallery_name":"gallerytest1", 
"selector":"SETPOSE", 
"symmetricFill":"true" 
} 

헤더 내가

'Content-Type:application/json', 
'app_id:app_id', 
'app_key:app_key' 

사용하고있다 curl.code이

<?php 
$ch = curl_init('some url'); 

$content= array(
'image'=>'some_image.jpg', 
'subject_id'=>'subtest1', 
'gallery_name'=>'gallerytest1', 
'selector'=>'SETPOSE', 
'symmetricFill'=>'true' 
); 

curl_setopt_array($ch, array(
CURLOPT_POST => TRUE, 
CURLOPT_RETURNTRANSFER => TRUE, 
CURLOPT_HTTPHEADER => array(
    'Content-Type:application/json', 
    'app_id:id', 
    'app_key:key' 
), 
CURLOPT_POSTFIELDS => json_encode($content) 
)); 

$response = curl_exec($ch); 

if($response === FALSE){ 
die(curl_error($ch)); 
} 

$responseData = json_decode($response, TRUE); 
?> 

아래입니다 발행물.

+0

error_reporting (E_ALL); ini_set ('display_errors', '1'); ' – AbraCadaver

+0

아직 빈 페이지를 표시했습니다. – shubhamj

+0

빈 페이지는 일반적으로 PHP 구문에 오류가 있음을 나타냅니다. [PHP 오류 메시지 켜기] (http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) 또는 서버 오류 로그를보십시오. –

답변

0

ini_set("allow_url_fopen", true); 
$jsonStr = file_get_contents("php://input"); //read the HTTP body. 
var_dump($jsonStr); 
echo "<br>"; 
$json = json_decode($jsonStr, true); 
print_r($json); 

그리고이

enter image description here

희망이 도움이 될 내 소스 형제

$data_string = array(
    'image'   =>'some_image.jpg', 
    'subject_id' =>'subtest1', 
    'gallery_name' =>'gallerytest1', 
    'selector'  =>'SETPOSE', 
    'symmetricFill' =>'true' 
); 
$data_string = json_encode($data_string); 
$ch = curl_init('http://localhost/testGuzzle/jsOnChange.php');      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                  
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                   
    'Content-Type: application/json',              
    'Content-Length: ' . strlen($data_string), 
    'app_id:id', 
    'app_key:key' 
    ));                 
$result = curl_exec($ch); 
if($result === FALSE){ 
    die(curl_error($ch)); 
}else{ 
    echo $result; 
} 

그리고 내 청취자 소스보십시오! xD

관련 문제