[PHP-users 35472] HTTP_ClientでxmlデータをPOSTする方法
岩堀嘉郎
uro @ iwahori.jp
2011年 1月 27日 (木) 09:36:09 JST
rubyで書かれた
#!/usr/bin/ruby
require 'uri'
require 'net/http'
Net::HTTP.version_1_1
HOST = "192.168.1.6"
#!/usr/bin/ruby
require 'uri'
require 'net/http'
Net::HTTP.version_1_1
HOST = "***.***.*.*"
PORT = "8000"
USER = "****"
PASSWD = "****"
CONTENT_TYPE = "application/xml"
req = Net::HTTP::Post.new("/orca14/appointmod?class=01")
record_in = <<EOF
<record>
<record name="appointreq">
<string name="Patient_ID">415006550</string>
<string name="Appointment_Date">2011-01-25</string>
<string name="Appointment_Time">15:00:00</string>
<string name="Appointment_Id">00001</string>
<string name="Department_Code">01</string>
<string name="Physician_Code">10002</string>
<string name="Appointment_Information">01</string>
</record>
</record>
EOF
record = ""
1.times {|i|
record += record_in.gsub("__X__", i.to_s)
}
BODY = "<data>#{record}</data>"
req.content_length = BODY.size
req.content_type = CONTENT_TYPE
req.body = BODY
req.basic_auth(USER, PASSWD)
puts req.body
Net::HTTP.start(HOST, PORT) {|http|
res = http.request(req)
puts res.body.size
puts res.body
}
というプログラムをphpで書き直したいのですが、
<?php
require_once 'HTTP/Client.php';
$url ="http://***.***.*.*:8000/orca14/appointmod?class=01";
$id ="****";
$pass="****";
$loginpara=array(
'user' => '$id',
'pass' => '$pass',
);
$data = "<data>
<record>
<record name=\"appointreq\">
<string name=\"Patient_ID\">415000025</string>
<string name=\"Appointment_Date\">2011-01-25</string>
<string name=\"Appointment_Time\">14:53:00</string>
<string name=\"Department_Code\">01</string>
<string name=\"Physician_Code\">10001</string>
<string name=\"Appointment_Information\">01</string>
<string name=\"Appointment_Note\">テストコメント</string>
</record>
</record>
</data>";
$client=& new HTTP_Client($logoinpara);
$client -> setDefaultHeader('Content-Type', 'application/xml');
$client ->post($url, $data);
$response = $client->currentResponse();
print_r($response);
?>
としてもなにもデータが送られていない様なレスポンスしか返ってきません。どこが悪いのでしょうか?
PHP-users メーリングリストの案内