POSTを使用してxmlリクエストを送信するためのスクリプトを作成しました。これはLinuxコマンドラインでは完全に機能しますが、php curlでは機能しません。これは私のxmlファイルであり、使用したコマンドです。
<?xml version="1.0"?>
<methodCall>
<methodName>test.echo</methodName>
<params>
<param><value><string>nbb</string></value></param>
<param><value><string>health check: 1436777963</string></value></param>
</params></methodCall>
curl -H "Content-Type: text/xml" -d @test.xml -X POST http:my.host:5862 -v
これは私のphpスクリプトです。
$url = 'http://my.host:5862';
#$requested = xml_gen($function_name,$epos,$time);
$requested = '<?xml version="1.0"?><methodCall><methodName>test.echo</methodName><params><param><value><string>nbb</string></value></param><param><value><string>health check: 1436777963</string></value></param></params></methodCall>';
#echo($requested);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_ENCODING ,"ISO-8859-1");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $requested);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
echo $response = curl_exec($ch);
curl_close($ch);
//Decoding the response to be displayed
echo xmlrpc_decode($response);
これは、PHP の cURL で発生するエラーです。
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 13 Jul 2015 15:26:05 GMT
Content-Type: text/XML
Content-Length: 0
Connection: keep-alive
Keep-Alive: timeout=20