Drupal::httpClient中post,get參數參考

  
      $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' => [],
    ];





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章