我正在尝试连接到合作伙伴的Web服务,以完成REST规范。要连接到他们的REST WS,我有一个连接URL('www.example.org/wservice/session'),我必须通过POST带来一个XML作为登录参数,这是我必须用来连接的XML结构他们:
<Payload>
<Header>
<CustomerID></CustomerID>
<Signature></Signature>
<PlainTextLength></PlainTextLength>
<Version>1.0</Version>
</Header>
<Body>
... stuff ...
</Body>
</Payload>
这应该给我带来一个TOKEN id,我会在登录后提前使用它来访问WS函数。
我拥有标题参数的所有值,但我不知道如何启动我的PHP脚本以建立正确的连接。
编辑1:这是我目前使用的代码:
$post_xml = "<Payload><Header><CustomerID>20266</CustomerID><Signature></Signature><PlainTextLength></PlainTextLength><Version>1.0</Version></Header><Body></Body></Payload>";
$url = "http://www.example.org/wservice/session";
$port = 80;
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off'))
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
if($port==443){
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}
$data = curl_exec($ch);