$httpclient = \Drupal::httpClient()->post($url, [
'form_params' => $post,
'headers' => [
'Referer' => $url,
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Firefox/45.0',
],
]);
$post之後的參數數組格式可參考如下:
// 位於class Client implements ClientInterface類裏面
private function applyOptions(RequestInterface $request, array &$options) 函數裏面。
$options = [
'form_params' => [],
'headers' => [
'Cookie' => '',
'Refer' => '',
'User-Agent' => '',
],
'multipart' => [],
'json' => [],
'decode_content' => [],
'body' => [],
'auth' => [
'basic' => '',
'digest' => '',
],
'query' => [],
'sink' => [],
'_conditional' => [],
];