不允许卷曲405

时间:2019-06-12 14:58:19

标签: php json ajax curl

在尝试使用PHP CURl时,我收到405方法不允许的错误响应。请找到下面的代码,并帮助我达到紧急状态

我需要酒店的价格

$ url ='https://www.npmjs.com/package/getenv';     $ ref ='https://otel.otello.az/api/wl_search/result';

$jso = my_curl($url,$ref);

var_dump($jso);

function my_curl( $url,$ref, $get_array=array(), $timeout=5003, $error_report=TRUE){

    $get_string = NULL;
    foreach ($get_array as $key => $val)
    {
        $get_string= $get_string. $key. '='. urlencode($val). '&';
    }

    $get_string = rtrim($get_string, '&');
    if (!empty($get_string)) $url .= '?' . $get_string;

    // START CURL
    $curl = curl_init();


    $header[] = "Accept: text/xml,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    // $header[] = "Cache-Control: max-age=0";
    // $header[] = "Connection: keep-alive";
    // $header[] = "Keep-Alive: 300";
    $header[] = "Origin: otel.otello.az";
    $header[] = "Content-Type: application/json";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Encoding: gzip, deflate, br";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE THIS BLANK
    $header[] = "Wl-Front: 1"; // BROWSERS USUALLY LEAVE THIS BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        $ref  );
   // curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    // curl_setopt( $curl, CURLOPT_POST, true);
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );
    //curl_setopt( $curl, CURLOPT_NOBODY, 0);
    curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, "POST");
    // THIS SEEMS TO LET IT WORK WITH HTTPS SITES
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE HANDLE CREATION OF ERROR MESSAGE
    if ($htm === FALSE)
    {
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}

0 个答案:

没有答案