curl PHP API错误:无效请求

时间:2015-12-11 14:12:39

标签: php html api curl

我刚从使用CUrl的php api中得到此错误:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>        
    <HEAD>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
        <TITLE>ERROR: The requested URL could not be retrieved</TITLE>
        <STYLE type="text/css">
            <!--BODY {
                background-color: #ffffff;
                font-family: verdana, sans-serif
            }
            PRE {
                font-family: sans-serif
            }
            -->
        </STYLE>
    </HEAD>

    <BODY>
        <H1>ERROR</H1>
        <H2>The requested URL could not be retrieved</H2>
        <HR noshade size="1px">
        <P> While trying to process the request:
            <PRE> POST /flight/1.0.0/book HTTP/1.1 Host: example.com
     Accept: */*
     Content-Length: 1058
     Content-Type: application/x-www-form-urlencoded
     Expect: 100-continue
      </PRE>
            <P> The following error was encountered:
                <UL>
                    <LI>
                        <STRONG> Invalid Request </STRONG> </UL>
                <P> Some aspect of the HTTP Request is invalid. Possible problems:
                    <UL>
                        <LI>Missing or unknown request method
                            <LI>Missing URL
                                <LI>Missing HTTP Identifier (HTTP/1.0)
                                    <LI>Request is too large
                                        <LI>Content-Length missing for POST or PUT requests
                                            <LI>Illegal character in hostname; underscores are not allowed </UL>
                    <P>Your cache administrator is
                        <A HREF="mailto:itdept@example.com">itdept@example.com</A>.
                        <BR clear="all">
                        <HR noshade size="1px">
                        <ADDRESS> Generated Fri, 11 Dec 2015 11:53:39 GMT by zeus.example.com (squid) </ADDRESS> </BODY>

    </HTML>

额外的desc。只是为了避免&#34;请添加更多细节&#34; ... 这是我的curl代码:

$req_array=array(               
    'id'=>'123','456',
    'reference_id'=>'abc123',
    'contact'=>$array_contact,
    'pax'=>$pax_array,
    'call_back_url'=>'http://example.com/issueTicket',                              
    'username'=>'username',             
    'password'=>'password'              
    );

    $url = 'http://example.com/test/1.0.0/book';

    //Initiate cURL.
    $ch = curl_init($url);  
    curl_setopt($ch, CURLOPT_POST, 1);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         
    curl_setopt($ch, CURLOPT_HEADER, 0);            
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);         
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
    $post=array();          
    $post['request'] = $request;
    /*this $request is an array contains the data i want to send*/
    $post = http_build_query($post,'','&');         
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);            

    //Execute the request
    $result = curl_exec($ch);
    curl_close($ch);

$ request包含嵌套的JSON关联数组:

  

{&#34; ORDER_ID&#34;:[&#34; 201501&#34;&#34; 201502&#34],&#34; REFERENCE_ID&#34;:&#34; 1a2b3c4d5f6g7h&#34; &#34;接触&#34; {&#34;标题&#34;:&#34;先生&#34;&#34;如first_name&#34;:&#34;珞巴族&#34;&#34 ;姓氏&#34;:&#34;珞巴族&#34;&#34; area_phone_code&#34;:&#34; 0812&#34;&#34; PHONE_NUMBER&#34;:&#34; 78493483&#34; &#34;电子邮件&#34;:&#34; example@example.com"}&#34; PAX&#34;:[{&#34;成年&#34;:[{&#34;标题&#34;:&#34;先生&#34;&#34;如first_name&#34;:&#34;珞巴族&#34;&#34;姓氏&#34;:&#34;珞巴族&#34;} ]&#34;子&#34;:[{&#34;标题&#34;:&#34; MSTR&#34;&#34;如first_name&#34;:&#34;子&#34;,& #34;姓氏&#34;:&#34;子&#34;&#34; DOB&#34;:&#34;二零一五年十一月二十零日&#34;}]},{&#34;成年&#34 ;:[{&#34;标题&#34;:&#34;先生&#34;&#34;如first_name&#34;:&#34;珞巴族&#34;&#34;姓氏&#34;:& #34;珞巴族&#34;}],&#34;子&#34;:[{&#34;标题&#34;:&#34; MSTR&#34;&#34;如first_name&#34;:&# 34;子&#34;&#34;姓氏&#34;:&#34;子&#34;&#34; DOB&#34;:&#34;二零一五年十一月二十〇日&#34;}]}] &#34; call_back_url&#34;:&#34; HTTP://example.com/issueTicket",& #34;用户名&#34;:&#34;用户名&#34;&#34;密码&#34;:&#34;密码&#34;}

任何人都可以给我解决此错误的方法吗?有用的解决方案将不胜感激

0 个答案:

没有答案