0

I'm struggling with php curl. This is the problem:

In the following code, if I pass $query as curl_init() parameter it doesn't work, and I get no error at all. But if I pass the exact content of $query to curl_init() the code works fine.

$query1 = "'user:passwd@192.168.0.199/cdtc-test/service.php/find/ca_objects?q=*'";
$curl = curl_init($query1);
$errmsg  = curl_error( $curl );
if (!$errmsg =='') {die($err.':'.$errmsg);}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header  = curl_getinfo( $curl );
print_r ($header);
$result = curl_exec ($curl);
curl_close ($curl);  

The result of print_r ($header) shows that the url is passed. I can't figure out what's wrong. Any ideas? Thanks in advance.

Array ( [url] => 'user:passwd@192.168.0.199/cdtc-test/service.php/find/ca_objects?q=*'
[content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 
[filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 
[namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0
[size_download] => 0 [speed_download] => 0 [speed_upload] => 0 
[download_content_length] => -1 [upload_content_length] => -1 
[starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => 
Array ( ) [redirect_url] => ) 
4

1 回答 1

1

我相信这一点:

$query1 = "'user:passwd@192.168.0.199/cdtc-test/service.php/find/ca_objects?q=*'";

应该是这样(注意删除了内部单引号):

$query1 = "user:passwd@192.168.0.199/cdtc-test/service.php/find/ca_objects?q=*";
于 2013-06-08T03:20:06.897 回答