我正在努力学习php curl。这就是问题所在:
在下面的代码中,如果我将$query
作为curl_init()
参数传递,则它不起作用,我根本没有错误。
但是,如果我将$query
的确切内容传递给curl_init()
,则代码可以正常工作。
$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);
print_r ($header)
的结果显示网址已通过。我无法弄清楚是什么
错误。有任何想法吗?提前谢谢。
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] => )
答案 0 :(得分: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=*";