首页 > 解决方案 > 将命令行 curl 转换为 PHP curl

问题描述

我需要帮助将 curl 命令转换为 PHP curl 命令

curl -vvvv -k -s -X POST --header 'Content-type: text/xml;charset="utf-8"' --header 'SOAPAction: vend' -u 'root':'1234' -d "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><vend xmlns=\"http://service.vti.co.uk/xsd\"><sequence>8076922343</sequence><origMsisdn>01166623832 </origMsisdn><destMsisdn>032030303</destMsisdn><amount>10</amount><tariffTypeId>1</tariffTypeId></vend></soapenv:Body></soapenv:Envelope>" https://121.200.1.223:443/services/vti ; echo;

我已经尝试了下面的代码,它给了我Error:SSL: no alternative certificate subject name matches target host name即使它在终端上运行良好。

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://121.200.1.223:443/services/vti');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><vend xmlns=\"http://service.vti.co.uk/xsd\"><sequence>8076922343</sequence><origMsisdn>01166623832 </origMsisdn><destMsisdn>032030303</destMsisdn><amount>10</amount><tariffTypeId>1</tariffTypeId></vend></soapenv:Body></soapenv:Envelope>");
curl_setopt($ch, CURLOPT_USERPWD, 'root' . ':' . ''1234'');

$headers = array();
$headers[] = 'Content-Type: text/xml;charset=\"utf-8\"';
$headers[] = 'Soapaction: vend';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

标签: phpcurlphp-curl

解决方案


推荐阅读