0
我遇到了一個奇怪的問題。cURL問題
我有一些簡單的線路CURL代碼來調用api服務。當運行Drupal(在瀏覽器和cli中的php文件)時,這段代碼運行得非常好,但是當文件包含在Drupal中(在引導後)時,它會以直觀的方式運行。
在正常情況下,API服務返回的結果有很多結果,但在Drupal中運行時,它只返回一個結果。
我懷疑Drupal正在改變CURL正在使用的設置,這正在改變API如何理解呼叫。
有誰知道問題可能是由什麼引起的?
下面的代碼是從我們在公共庫中編寫的api類文件派生而來的。我們計劃將來在其他PHP項目中使用它們。
下面是代碼:
$params = array(
'domain' => array(
'www.domain1.com',
'www.domain2.info',
'www.domain3.in.th',
'www.domain4.com',
'www.domain5.in',
)
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://api.postrank.com/v2/domain/activity?appkey=123456&format=json',
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($params)
));
$response = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
print_r($response);
UPDATE 1:從CURLOPT_VERBOSE和curl_getinfo
CLI版 輸出:
* About to connect() to api.postrank.com port 80 (#0) * Trying 75.101.138.238... * connected * Connected to api.postrank.com (75.101.138.238) port 80 (#0) > POST /v2/domain/activity?appkey=123456&format=json HTTP/1.1 Host: api.postrank.com Accept: */* Content-Length: 159 Content-Type: application/x-www-form-urlencoded http://api.postrank.com/v2/domain/activity?appkey=123456&format=json [content_type] => text/javascript [http_code] => 200 [header_size] => 172 [request_size] => 355 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.968 [namelookup_time] => 0 [connect_time] => 0.437 [pretransfer_time] => 0.437 [size_upload] => 159 [size_download] => 998 [speed_download] => 1030 [speed_upload] => 164 [download_content_length] => 998 [upload_content_length] => 0 [starttransfer_time] => 0.968 [redirect_time] => 0 )
Drupal的版本:
* About to connect() to api.postrank.com port 80 (#0) * Trying 75.101.138.238... * connected * Connected to api.postrank.com (75.101.138.238) port 80 (#0) > POST /v2/domain/activity?appkey=123456&format=json HTTP/1.1 Host: api.postrank.com Accept: */* Content-Length: 175 Content-Type: application/x-www-form-urlencoded http://api.postrank.com/v2/domain/activity?appkey=123456&format=json [content_type] => text/javascript [http_code] => 200 [header_size] => 172 [request_size] => 371 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.905 [namelookup_time] => 0 [connect_time] => 0.437 [pretransfer_time] => 0.437 [size_upload] => 175 [size_download] => 126 [speed_download] => 139 [speed_upload] => 193 [download_content_length] => 126 [upload_content_length] => 0 [starttransfer_time] => 0.905 [redirect_time] => 0 )
你的意思是'&'? – RRStoyanov 2011-05-29 21:18:25
@RRStoyanov,是的,我的意思是'&'。 – lordg 2011-06-02 22:16:56