drupal_http_request send你的客户在空格时发出了格式错误或非法的请求

时间:2014-08-29 08:21:05

标签: php http drupal httprequest freebase

drupal_http_request在网址中的空格时发送“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)”类型后面有空格。如果我删除空间然后它的工作正常。但是空间给出了400个错误的请求错为什么呢?

2 个答案:

答案 0 :(得分:0)

$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);

这解决了我的问题。

答案 1 :(得分:0)

'正确'的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));