Post 其他服务器的参数
Post Parameter to other Server
我想用 php curl 将参数发送到 api。内容类型是 xml 但是当我发送这个参数时我得到了一个错误,如:
Notice: Use of undefined constant CURLOPT_MUTE - assumed 'CURLOPT_MUTE' in C:\xampp\htdocs\router.php on line 20
Warning: curl_setopt() expects parameter 2 to be long, string given in C:\xampp\htdocs\router.php on line 20
我的 curl 代码是:
$xml_data ='<?xml version="1.0" encoding="utf-8"?>'.
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
'<soap:Body>'.
'<getMassBarcode xmlns="http://tempuri.org/">'.
'<UserName>username</UserName>'.
'<Password>password</Password>'.
'<PostNodeCode>19387</PostNodeCode>'.
'<CityCode>1</CityCode>'.
'<TypeCode>11</TypeCode>'.
'</getMassBarcode>'.
'</soap:Body>'.
'</soap:Envelope>';
$URL = "http://poffice.post.ir/webbarcode/getbarcode.asmx";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
我该如何解决?
注意:我用 post man 来测试 api 。在 postman raw 选项中,我输入了 xml 内容。效果很好
您可能正在使用更高版本的 curl。刚刚从代码中删除了该行,它应该适合您。
curl setopt 页面上写着:
Removed in cURL 7.15.5 (You can use CURLOPT_RETURNTRANSFER instead)
我想用 php curl 将参数发送到 api。内容类型是 xml 但是当我发送这个参数时我得到了一个错误,如:
Notice: Use of undefined constant CURLOPT_MUTE - assumed 'CURLOPT_MUTE' in C:\xampp\htdocs\router.php on line 20
Warning: curl_setopt() expects parameter 2 to be long, string given in C:\xampp\htdocs\router.php on line 20
我的 curl 代码是:
$xml_data ='<?xml version="1.0" encoding="utf-8"?>'.
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
'<soap:Body>'.
'<getMassBarcode xmlns="http://tempuri.org/">'.
'<UserName>username</UserName>'.
'<Password>password</Password>'.
'<PostNodeCode>19387</PostNodeCode>'.
'<CityCode>1</CityCode>'.
'<TypeCode>11</TypeCode>'.
'</getMassBarcode>'.
'</soap:Body>'.
'</soap:Envelope>';
$URL = "http://poffice.post.ir/webbarcode/getbarcode.asmx";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
我该如何解决?
注意:我用 post man 来测试 api 。在 postman raw 选项中,我输入了 xml 内容。效果很好
您可能正在使用更高版本的 curl。刚刚从代码中删除了该行,它应该适合您。
curl setopt 页面上写着:
Removed in cURL 7.15.5 (You can use CURLOPT_RETURNTRANSFER instead)