使用GET wierd结果发送vars的php curl [英] php curl sending vars using GET wierd results
问题描述
我试图在远程站点的页面中调用URL。决定使用卷曲。在远程站点上,url vars显示为:
$ _ REQUEST数组
(
[var1] => val1
[amp; var2] => val2
[amp; var3] => val3
)
被调用的网址是:
http://网站。 com / controller / action.php?var1 = val1& var2 = val2& var3 = val3
我没有在url中使用& amp;
,但请求全局有或几乎 - 它有 amp;
而不是& 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);
在此之后,我又跑了另一个curl请求,我仍然登录,所以问题不是cookie 。由于使用$ _POST的最后一个请求(登录表单)已将CURLOPT_POST设置为0,并且CURLOPT_HTTPGET设置为1.
以下是$ info的输出:
info数组
(
[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
[redirec t_time] => 0
[certinfo] => Array
(
)
)
if我复制并通过$ 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有一个内置函数可以做同样的事情。
i'm trying to call a url in a page on a remote site. Decided on using curl. On the remote site the url vars are showing as:
$_REQUEST Array
(
[var1] => val1
[amp;var2] => val2
[amp;var3] => val3
)
the url being called is:
http://site.com/controller/action.php?var1=val1&var2=val2&var3=val3
Notice that I'm not using &
in the url, but the request global has it, or nearly - it has amp;
instead of &
and not &
like I used!!! Not that it should have any of them.
The curl object has logged in to a form, set cookies, posted a form on another page, and now this is the last link I have to follow.
here is the php i'm using:
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);
I've ran another curl request after this and I'm still logged in so issue is not cookies. Because the last request (the login form) used $_POST have have set the CURLOPT_POST to 0 and the CURLOPT_HTTPGET to 1. Here is the output from $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
(
)
)
if i copy and past $info['url'] into the browser it works. Completely lost, hours lost on the clock, any help would be appreciated ;)
Try modifying your code as follows:
$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);
EDIT
Removed custom encode function as per Brad's comment - you don't need it, as PHP has a build-in function that does the same thing.
这篇关于使用GET wierd结果发送vars的php curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!