POST request
function Postxmlcurl ($url, $xml) {
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_postfields, $xml);
curl_setopt ($ch, Curlopt_httpheader, Array (
' content-type:text/xml; Charset=utf-8 ',
' content-length: '. Strlen ($xml))
);
$response = curl_exec ($ch);
if ($response) {
curl_close ($ch);
return $response;
} else {
curl_close ($ch);
return false;
}
}
$response = Postxmlcurl ($url, $xml);
if (! $response) {
//todo return
false;
} <span style= "White-space:pre" > </span>
$response = simplexml_load_string ($response, ' SimpleXMLElement ', libxml_nocdata);
if (!is_object ($response)) {
//todo return
false;
}
$result = (array) $response;
Todo
Request with certificate validation
function Post_xml_curl ($url, $xml, $cert = ', $key = ', $certpwd = ') {
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_httpheader, Array (
' content-type:text/xml; Charset=utf-8 ',
' content-length: '. Strlen ($xml))
);
curl_setopt ($ch, Curlopt_ssl_verifypeer, 1);
curl_setopt ($ch, Curlopt_ssl_verifyhost, 1);
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_postfields, $xml);
if (Isset ($cert) && isset ($key) && isset ($certpwd)) {
curl_setopt ($ch, Curlopt_sslcerttype, ' PEM ') );
curl_setopt ($ch, Curlopt_sslcert, $cert);
curl_setopt ($ch, CURLOPT_SSLCERTPASSWD, $certpwd);
curl_setopt ($ch, Curlopt_sslkeytype, ' PEM ');
curl_setopt ($ch, Curlopt_sslkey, $key);
}
$response = curl_exec ($ch);
Curl_close ($ch);
return $response;
}