cURL坏请求错误400
问题描述:
我尝试使用cURL与PHP,但我有一个错误400“坏请求” 你能帮我吗?cURL坏请求错误400
我尝试了很多东西,但它不工作。 我在这段代码中修改了带有错误URL的URL。
我使用soapUI。
谢谢,我的英语不好对不起
<?php
$participans_number = 1;
$soapUrl = "http://testservices.aireur.com/aireur-ws/Booking?wsdl";
$participans = '<book:participants>';
for($i = 0; $i<$participans_number; $i++){
$participans = $participans .
'<book:Participant>
<book:Civite> Mr </book:Civite>
<book:Nom>SARE</book:Nom>
<book:Prenom>Claude</book:Prenom>
<book:DateNaissance>12/11/1990</book:DateNaissance>
<book:Phone>0606060606</book:Phone>
<book:Adresse1>Via Lo 25</book:Adresse1>
<book:CodePostal>57025</book:CodePostal>
<book:Ville>Piombino</book:Ville>
<book:Pays>IT</book:Pays>
<book:Email>[email protected]</book:Email>
</book:Participant>';
}
$participans = $participans . '</book:participants>';
$xml_post_string ='<?xml version="1.0"?><soapenv:Envelope xmln:soapenv="http://schemas.xmlsaop.org/soap/envelope/" xmlns:book="bookingservices.aireur.com/">
<soapenv:Header/>
<soapenv:Body>
<book:MakeBooking>
<!--Optional : -->
<book:agAccount>aireur9</book:agAccount>
<book:agProd_1_ToI>aireur9</book:agProd_1_ToI>
<!--Optional : -->
<book:agAgencyId>000000015139</book:agAgencyId>
<!--Optional : -->
<book:agProd_1_RoomType>test</book:agProd_1_RoomType>
<!--Optional : -->
<book:agProd_1_Code>test</book:agProd_1_Code>
<!--Optional : -->
<book:trFromDate>12/11/2016</book:trFromDate>
<!--Optional : -->
<book:trToDate>18/11/2016</book:trToDate>'.
$participans . '
<book:options></book:options>
<book:reference>aireurIT1</book:reference>
<!--Optional : -->
</book:MakeBooking>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"POST http://testservices.aireur.com/aireur-ws/Booking HTTP/1.1",
"Host: http://bookingservices.aireur.com/",
"SOAPAction: http://bookingservices.aireur.com/MakeBooking",
"Content-Type: text/xml;charset=UTF-8",
"Content-Lenght:". strlen($xml_post_string)
);
//Booking request - end
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$reponse = curl_exec($ch);
curl_close($ch);
echo $reponse;
?>
答
- 从$头阵列
"POST http://testservices.aireur.com/aireur-ws/Booking HTTP/1.1"
...删除这个,因为它是不是一个真正的头并会使请求严重畸形。
请勿自行设置
Host:
。它只会冒你做错的风险,并且curl会根据你使用的URL自己正确地做它。与主机,不设置
Content-Length:
,让卷曲集它本身根据你要求它发送的实际数据。
检查Content-Lenght中的长度。 – anwerj