doubo6658 2016-09-23 07:17
浏览 151

cURL错误请求错误400

I try to use cURL with PHP but I have an error 400 "bad request" Can you help me please ?

I try a lot of things but it is not working. I have modify the URL with false URL in this code.

I use soapUI.

Thanks, and sorry for my bad English

<?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>test@test.fr</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;

?>
  • 写回答

2条回答 默认 最新

  • dongmu1951 2016-09-23 07:47
    关注
    1. Remove this from the $headers array

    "POST http://testservices.aireur.com/aireur-ws/Booking HTTP/1.1"

    ... as it isn't really a header and will make the request severely malformed.

    1. Don't set Host: yourself. It will only risk you do it wrong and curl will do it correctly itself based on the URL you use.

    2. As with Host, don't set Content-Length: and let curl set it itself based on the actual data you ask it to send.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀