나는 cURL을 사용하지만 이제는 서버에서 데이터를 요청할 때까지 사용했습니다. 하지만 이제 API를 작성하고 데이터가 cURL로 요청됩니다. 하지만 서버가 cURL 요청에서 데이터를 읽는 방법을 알지 못합니다.cURL 요청을위한 서버 측 스크립트
이 내 "클라이언트 서버"측의 요구입니다 :
function sendRequest($site_name,$send_xml,$header_type=array('Content-Type: text/xml'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$site_name);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$send_xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header_type);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec($ch);
return $result;
}
$xml = "<request>
<session>
<user>exampleuser</user>
<pass>examplepass</pass>
</session>
</request>";
$sendreq = sendRequest("http://sitename.com/example.php",$xml);
echo $sendreq;
어떻게 내가 어떤 사용자를 읽고 요청에서 전달할 수 있도록 "주 서버"측 스크립트를 작성해야합니까 ??? 정말 고마워요.
PHP가 서버에서 실행됩니다 ... 이것은 의미가 없습니다. –
@DigitalChris 내가 클라이언트라고 할 때 "클라이언트 서버"는 응용 프로그램을 실행하고 서버는 "주 서버"입니다 – mandza
XML을 사용해야하는 경우 example.php에 xml 파서가 필요합니다. XML 파서의 오버 헤드를 피하기 위해보다 유연하게 HTTP 게시 요청을 사용하는 경우. –