PHP cURL - 在get请求中打印出不完整的url

时间:2017-12-12 09:12:51

标签: php http curl

我用curl做了这个请求,我试图调用一个url传递一个参数给它,但似乎没有正常工作。这是我的curl请求的php代码:

$curl = curl_init();
$params = array('code'=> '123123');
$query = http_build_query($params);
try{
    curl_setopt($curl, CURLOPT_URL, 'https://www.website.com/foo/addProduct?'.$query);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLINFO_HEADER_OUT, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
    $resp = curl_exec($curl);

    //DEBUG INFO
    $information = curl_getinfo($curl);
} catch (Exception $e) {
    echo $e;
}

现在,当我尝试打印curl的请求和响应标头时,我得到了这种情况:

Array
(
[url] => https://www.website.com/
[content_type] => text/html;charset=ISO-8859-1
[http_code] => 200
[header_size] => 1088
[request_size] => 1209
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 0.706971
[namelookup_time] => 3.3E-5
[connect_time] => 3.4E-5
[pretransfer_time] => 9.6E-5
[size_upload] => 0
[size_download] => 53855
[speed_download] => 76177
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0.201504
[redirect_time] => 0.447898
[redirect_url] => 
[primary_ip] => 193.42.160.33
[certinfo] => Array
    (
    )

[primary_port] => 443
[local_ip] => 192.168.1.51
[local_port] => 61262
[request_header] => GET / HTTP/1.1
)

我希望网址

https://www.website.com/foo/addProduct?code=123123

我是对的吗?

1 个答案:

答案 0 :(得分:0)

你是完全正确的,代码生成 public void setSelecteditem(int selecteditem) { this.selectedItem = selecteditem; for (int i=0;i<moviesList.size();i++){ moviesList.get(i).setCenterSelected(false); Log.d("CSA","## moviesList.get(i).isCenterSelected() : "+ moviesList.get(i).isCenterSelected()); } moviesList.get(selecteditem).setCenterSelected(true); notifyDataSetChanged(); } 的唯一方法是curl是Location-redirected(因为你使用了[url] => https://www.website.com/)。

删除CURLOPT_FOLLOWLOCATION(由于https://bugs.php.net/bug.php?id=65348),然后执行curl_setopt ( $curl, CURLINFO_HEADER_OUT, true );,您应该可以自己查看。