php curl使用GET wierd结果发送变种

Dai*_*thí 2 php curl get

我正在尝试在远程站点的页面中调用URL.决定使用卷曲.在远程站点上,URL变量显示为:

$_REQUEST   Array
(
    [var1] => val1
    [amp;var2] => val2
    [amp;var3] => val3
)
Run Code Online (Sandbox Code Playgroud)

被调用的网址是:

http://site.com/controller/action.php?var1=val1&var2=val2&var3=val3
Run Code Online (Sandbox Code Playgroud)

请注意,我没有&在网址中使用,但请求全局使用它,或者差不多 - 它amp;代替&并且&不像我使用的那样!不是说它应该有任何一个.

curl对象已登录到表单,设置cookie,在另一页上发布表单,现在这是我必须遵循的最后一个链接.

这是我正在使用的PHP:

    curl_setopt($this->ch, CURLOPT_URL, "http://site.com/controller/action.php?var1=val1&var2=val2&var3=val3");
    curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($this->ch, CURLOPT_REFERER, "http://site.com/");
    curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
    curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie);
    curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie);
    curl_setopt($this->ch, CURLOPT_POST, 0);
    curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
    $output = curl_exec($this->ch);
    $info = curl_getinfo($this->ch);
Run Code Online (Sandbox Code Playgroud)

在此之后我又运行了另一个curl请求,我仍然登录,因此问题不是cookie.因为使用$ _POST的最后一个请求(登录表单)已经将CURLOPT_POST设置为0并且将CURLOPT_HTTPGET设置为1.这是$ info的输出:

info    Array
(
    [url] => http://site.com/controller/action.php?var1=val1&var2=val2&var3=val3
    [content_type] => text/html; charset=utf-8
    [http_code] => 403
    [header_size] => 403
    [request_size] => 541
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.781186
    [namelookup_time] => 3.7E-5
    [connect_time] => 3.7E-5
    [pretransfer_time] => 4.2E-5
    [size_upload] => 1093
    [size_download] => 3264
    [speed_download] => 4178
    [speed_upload] => 1399
    [download_content_length] => 3264
    [upload_content_length] => 0
    [starttransfer_time] => 0.781078
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

)
Run Code Online (Sandbox Code Playgroud)

如果我复制并将$ info ['url']复制到浏览器中就可以了.完全丢失,时钟丢失了几小时,任何帮助将不胜感激;)

Eli*_*lie 5

尝试按如下方式修改代码:

$data = array('val1'=>"val1", 'val2'=>"val2", 'val3'=>"val3");
curl_setopt($this->ch, CURLOPT_URL, "http://site.com/controller/action.php");
curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_REFERER, "http://site.com/");
curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($this->ch, CURLOPT_POST, 0);
curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
$output = curl_exec($this->ch);
$info = curl_getinfo($this->ch);
Run Code Online (Sandbox Code Playgroud)

编辑

根据Brad的评论删除了自定义编码功能 - 你不需要它,因为PHP有​​一个内置函数可以做同样的事情.