XML 데이터를 게시하여 작동하는 간단한 API 인 php를 사용하여 사용자 정의 api를 작성했습니다. 내가 API에 게시하기 위해 노력하고있다 코드는 다음과 같습니다송신 응답 - PHP API
<?php
$postdata = file_get_contents("php://input");
$xml = simplexml_load_string($postdata);
$first = $xml->first;
$last = $xml->last;
$email = $xml->email;
$phone = $xml->phone;
?>
가 그럼 난 그 PHP 변수를 취하고로 전송 님의 다른 측면에
<?php
$xml_data = '<document>
<first>'.$first.'</first>
<last>'.$last.'</last>
<email>'.$email.'</email>
<phone>'.$phone.'</phone>
<body>TEST</body>
</document>';
$URL = "url";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$Response = curl_exec($ch);
curl_close($ch);
echo "Responce= ".$responce;
?>
, 코드 위의 게시물 데이터베이스 ..이 코드는 모두 작동 중입니다 !!
하지만 내 질문은 : 게시 측에 응답을 어떻게 보냅니 까? curl_init을 사용하여 curl_exec으로 보내려면 어떻게해야합니까?
도움이 될 것입니다. 당신에게 제이슨
에서 돌아 볼 수 다음을 수행 후 데이터를 처리하는 스크립트, XML 응답을 반환? – Madbreaks
실수, 미안 해요! 출력과 닫기를 꺼내고 응답과 닫기를 남깁니다. – user1789437