需要用一些字段的post请求的api,但我不知道字段将被添加到哪里!! (在 GET 请求中,我像任何请求一样在 url 中添加字段)
API 代码
`
$apiKey = "8z8a7tupn5hubhjxqh8ubuz7";
$sharedSecret = "jsSJq2msbU";
$signature = hash("sha256", $apiKey.$sharedSecret.time());
$endpoint = "https://api.test.hotelbeds.com/activity-api/3.0/activities";
$request = new \http\Client\Request("POST",
$endpoint,
[ "Api-Key" => $apiKey,
"X-Signature" => $signature,
"Accept" => "application/json" ,
]);
$client = new \http\Client;
$client->enqueue($request)->send();
$response = $client->getResponse();
echo "<pre>";
print_r($response->getBody());
echo "</pre>";
api 说
The available filters for the search is listed below.
It contains an array of filter with the following structure:
[{"searchFilterItems": [{"type": "destination", "value": "BCN"}]}]
The Object “searchFilterItems” contains the following attributes: type > and value.
The following examples illustrate the different types and values for > each filter:
Country
{"type": "country", "value": "PT"}
最佳答案
我遇到了同样的问题,花了我一段时间才弄明白。原来你需要使用 Body 类来表示帖子数据。
$msg = new http\Message\Body();
$msg->addForm([
'field1' => 'value',
'field2' => 'value2'
]);
$headers = null;
$request = new http\Client\Request('POST', 'https://example.com', $headers, $msg);
$client = new http\Client();
$client->enqueue($request);
$client->send();
$response = $client->getResponse();
在 Message 和 Body 类中还有一些方法可以用于包含文件等。
关于httprequest - 我如何在 pecl_http 库中使用发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37511255/