Php Curl登录到未进行身份验证的应用程序

Php Curl登录到未进行身份验证的应用程序,php,curl,Php,Curl,我试图登录一个webapp来检索一个特定的文件,但我似乎无法在应用中进行身份验证,更不用说抓取一个文件了 不确定如何对此进行故障排除。虽然它可能是隐藏字段,但似乎向它们传递值并没有什么不同 function gla_fetchlist() { $username = 'xxx@xxx.com'; $password = 'xxxx'; $loginUrl = 'https://guestlistapp.com/login'; $content = file_get_contents('ht

我试图登录一个webapp来检索一个特定的文件,但我似乎无法在应用中进行身份验证,更不用说抓取一个文件了

不确定如何对此进行故障排除。虽然它可能是隐藏字段,但似乎向它们传递值并没有什么不同

function gla_fetchlist() {

$username = 'xxx@xxx.com';
$password = 'xxxx';
$loginUrl = 'https://guestlistapp.com/login';


$content = file_get_contents('https://guestlistapp.com/login');

$doc = new DOMDocument();
$doc->loadHTML($content);
$tags = $doc->getElementsByTagName('input');
foreach ($tags as $tag) {
    if($tag->getAttribute('name') === 'authenticity_token') {
         $token = $tag->getAttribute('value');

    }
    if($tag->getAttribute('name') === 'utf8') {
         $utf8 = $tag->getAttribute('value');

    }
    if($tag->getAttribute('name') === '_method') {
         $method = $tag->getAttribute('value');

    }

}


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password.'&authenticity_token='.$token.'&utf8='.$utf8.'&_method='.$method);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec($ch);

echo $store;

}
这是调试日志

* Re-using existing connection! (#0) with host guestlistapp.com
* Connected to guestlistapp.com (173.255.229.91) port 443 (#0)
> POST /login.php HTTP/1.1
Host: guestlistapp.com
Accept: */*
Content-Length: 130
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 130 out of 130 bytes
< HTTP/1.1 404 Not Found
< Server: nginx
< Date: Mon, 16 Feb 2015 16:04:26 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 666
< Connection: keep-alive
< Status: 404 Not Found
< Strict-Transport-Security: max-age=31536000
< X-Request-Id: ff28bda2e9db2e42f4a383f8c5a969d5
< X-Runtime: 0.008811
< X-Rack-Cache: invalidate, pass
< 
* Connection #0 to host guestlistapp.com left intact

尝试curl\u setopt$ch,CURLOPT\u SSL\u VERIFYPEER,false;。仍然没有进行身份验证。您返回404错误,这意味着无法找到该页面。表单发布到的操作是/sessions,因此您必须尝试将数据发布到该url。更改$loginUrl=太多$loginUrl=是否有效?它似乎也给出了404。