Bastien:
-----Mensagem original-----
De: Bastien Koert [mailto:[email protected]]
Enviada em: quinta-feira, 4 de outubro de 2012 11:54
Para: PHP-General
Assunto: [PHP] cURL issues posting to an end point
Hi All,
I have a page that receives third party data into my app, xml data via https
post. This works fine and I receive the data as expected. The issue I am
facing is around posting XML data back as a synchronous response to the post
I receive. I am using the following code:
function sendXMLConfirmation($data)
{
/*
* XML Sender/Client.
*/
// Get our XML. You can declare it here or even load a file.
$xml_builder = '<?xml version="1.0" encoding="utf-8"?>
<Envelope version="01.00">
<Sender>
<Id/>
<Credential>25412</Credential>
</Sender>
<Recipient>
<Id/>
</Recipient>
<TransactInfo
transactType="response">
<TransactId>'.$hash.'</TransactId>
<TimeStamp>'.date("Y-m-d H:m
").'</TimeStamp>
<Status>
<Code>200</Code>
<ShortDescription>Success</ShortDescription>
<LongDescription>CANDIDATE Data transfer was a success</LongDescription>
</Status>
</TransactInfo>
<Packet>
<PacketInfo
packetType="response">
<PacketId>1</PacketId>
<Action>SET</Action>
<Manifest>Manifest
Data</Manifest>
<Status>
<Code/>
<ShortDescription/>
<LongDescription/>
</Status>
</PacketInfo>
<Payload><![CDATA[]]></Payload>
</Packet>
</Envelope>
';
// We send XML via CURL using POST with a http header of text/xml.
$ch = curl_init();
$url =
'https://staging.somesite.com/Sprocessor/DispatchMessage.asmx';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // for https
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
----- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
----- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
--- NEW ----
$sPost = '/Sprocessor/DispatchMessage.asmx';
$sHost = ' https://staging.somesite.com';
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'User-Agent: My Program',
'Accept-Encoding: gzip, deflate',
'POST ' . $sPost . ' HTTP/1.1',
'Host: ' . $sHost,
'Content-type: application/soap+xml; charset="utf-8"',
'Content-Length: ' . strlen($xml_builder)
);
---- END NEW -----
//Execute the request and also time the transaction ( optional )
$start = array_sum(explode(' ', microtime()));
$result = curl_exec($ch);
curl_close($ch);
// Print CURL result.
echo $ch_result;
}
The endpoint recipient says they are not receiving the data and I am at a
loss to figure out why. Any insight would be appreciated.
Thanks,
--
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php