私はphpを使用してカスタムAPIを構築しました。これは、xmlデータを投稿することで機能する単純なAPIです。APIに投稿するために取り組んでいるコードは次のとおりです。
<?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;
?>
一方、上記のコードは次の場所に投稿されます。
<?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変数を取得してデータベースに送信します..このコードはすべて機能しています!!
しかし、私の質問は次のとおりです。投稿側に応答を返すにはどうすればよいですか? curl_init を使用して curl_exec に送信するにはどうすればよいですか?
どんな助けでも素晴らしいでしょう!ありがとうジェイソン