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)"类型后面有空格。如果我去掉空间,它就可以工作了。但是空间给出了400个坏请求错误。为什么?
正确的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));
$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);
这解决了我的问题。