【问题标题】:drupal_http_request send Your client has issued a malformed or illegal request when spacesdrupal_http_request send 您的客户端在空格时发出了格式错误或非法的请求
【发布时间】:2014-08-29 08:21:05
【问题描述】:

drupal_http_request 在 url 中有空格时发送“Your client has issued a malformed or illegal request”:

$uri = "https://www.googleapis.com/freebase/v1/search?query=&prefixed=true&limit=10&output=(type )&lang=en";
 $options = array(
  'method' => 'GET',
  'timeout' => 3,
  'headers' => array(
    'Accept' => 'application/json',
  ),
);

$result = drupal_http_request($uri, $options);

" &output=(type) " type 后面有空格。如果我删除空间,那么它工作正常。但空间给出 400 bad request 错误。为什么?

【问题讨论】:

    标签: php http drupal httprequest freebase


    【解决方案1】:

    “正确”的 Drupal 方式:

    $service_url = 'https://www.googleapis.com/freebase/v1/search';
    $params = array(
      'query' => $search_string,
      'output' => '(description owner)',
      'filter' => '(any type:product type:brand)',
      'limit' => YILD_FREEBASE_MAX_HITS,
      'prefixed' => 'true',
      'lang' => $lang ,
    );
    
    $uri = url($serivce_url, array('query' => $params, 'external' => TRUE));
    

    【讨论】:

      【解决方案2】:
      $service_url = 'https://www.googleapis.com/freebase/v1/search';
        $params = array(
          'query' => $search_string,
          'output' => '(description owner)',
          'filter' => '(any type:product type:brand)',
          'limit' => YILD_FREEBASE_MAX_HITS,
          'prefixed' => 'true',
          'lang' => $lang ,
      
        );
      $uri = $service_url . '?' . http_build_query($params);
      

      这解决了我的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-26
        • 1970-01-01
        • 1970-01-01
        • 2021-12-25
        • 1970-01-01
        • 2012-10-18
        • 1970-01-01
        • 2012-06-18
        相关资源
        最近更新 更多