使用GET wierd结果发送变量的php curl
我正在尝试调用远程站点页面中的url。决定使用curl。在远程站点上,url变量显示为:使用GET wierd结果发送变量的php curl,php,curl,get,Php,Curl,Get,我正在尝试调用远程站点页面中的url。决定使用curl。在远程站点上,url变量显示为: $_REQUEST Array ( [var1] => val1 [amp;var2] => val2 [amp;var3] => val3 ) 正在调用的url是: http://site.com/controller/action.php?var1=val1&var2=val2&var3=val3 请注意,我没有使用&,但请求全局拥
$_REQUEST Array
(
[var1] => val1
[amp;var2] => val2
[amp;var3] => val3
)
正在调用的url是:
http://site.com/controller/action.php?var1=val1&var2=val2&var3=val3
请注意,我没有使用&,但请求全局拥有它,或几乎拥有它代码>而不是&代码>而不是像我以前那样的&
!!!并不是说它应该有它们中的任何一个
curl对象已经登录到表单,设置cookies,在另一个页面上发布表单,现在这是我必须遵循的最后一个链接
以下是我正在使用的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);
在此之后,我运行了另一个curl请求,但我仍在登录,所以问题不是cookies。因为上次使用$\u POST的请求(登录表单)已将CURLOPT\u POST设置为0,将CURLOPT\u 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
(
)
)
如果我将$info['url']复制到浏览器中,它就会工作。完全丢失,时间丢失,任何帮助都将不胜感激;) 尝试按如下方式修改代码:
$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);
编辑
根据Brad的评论删除了自定义编码函数-您不需要它,因为PHP有一个内置函数,可以做同样的事情。。。。。http 403发生在我的代码中,因为在$\u GET[]或$\u REQUEST[]中找不到$var2。当http\u build\u query()
工作正常时,为什么要编写自己的编码函数?只是从我正在处理的当前代码库中获取了这个函数-实际上不知道最初的开发人员为什么这样编写它。我更新了我的答案以反映这一点。这似乎是一篇帖子,但op希望得到一个答案。。想法?不,将CURLOPT_POST设置为0可以解决这个问题。我认为OP面临的问题是URL编码——他传递的是被编码的字符,而不是按字面意思处理URL。