我正在尝试使用 PHP 通过 cURL 发送 POSTDATA,但我认为 post 没有发送
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
$t = curl_exec($ch);
不知道为什么,但我试图登录一个页面,当我转储 $t 时,我总是看到表单,curl_error 是空的,我该怎么做才能调试这个?试图登录的页面不是我的!
我有一个模拟 cURL 的本地表单,它可以:
<form action="$url" method="POST">
<input type="hidden" name="username" value="$uspw" />
<input type="hidden" name="password" value="$uspw" />
<input type="submit" value="Send" />
</form>
它登录 $url! 这是我在 cURL 中发送到 POSTFIELDS 的 $data
$data = array('username' => $uspw,
'password' => $uspw);
是的..用户和密码是一样的
收到的标头:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Sun, 25 Nov 2012 05:23:19 GMT
Server: Apache
Cache-Control: no-cache="set-cookie"
Content-Length: 4822
Set-Cookie: SESSIONID_portalApp=xxxxxx!-xxx!xxx; path=/
Content-Language: en
X-Powered-By: Servlet/2.4 JSP/2.0
Content-Type: text/html; charset=ISO-8859-1
在此之后,我再次收到所有表格......
$data = array('username' => $uspw,
'password' => $uspw);
$header = array('Origin: xxx',
'Content-Type: application/x-www-form-urlencoded',
'Connection: keep-alive',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Cache-Control: max-age=0',
'Except:',
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding:gzip,deflate,sdch',
'Accept-Language:es-ES,es;q=0.8',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'xxx.txt');
curl_setopt($ch, CURLOPT_REFERER, 'xxxx');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
$t = curl_exec($ch);
谢谢你!