我如何构造POST卷曲并确保没有格式问题或传递多余的字符

问题描述 投票:0回答:1

我想知道我是否可以在格式化PHP Curl Test方面获得一些帮助。

https://developer.pricelinepartnernetwork.com/documentation/hotel#/paths/~1getExpress.Book/post

需要确保没有格式问题或传递多余的字符。

非常感谢

curl php-curl
1个回答
0
投票
<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "{{ server }}/hotel/getAutoSuggestV2?format=json2&refid={{ refid }}&api_key={{ api_key }}&string=winni",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Cache-Control: no-cache"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

https://www.labnol.org/code/19998-php-curl-example

另一个很棒的资源:https://rapidapi.com/blog/how-to-use-an-api-with-php/

© www.soinside.com 2019 - 2024. All rights reserved.