【发布时间】:2017-07-12 00:20:17
【问题描述】:
我找到了一个脚本并对其进行了修改,希望返回登录页面的内容。但是,页面似乎不允许我登录。
使用 var_dump($_POST); 和 print_r($_POST); 给我一个空白数组:
array(0) {
}
Array
(
)
所以我不知道该怎么做。网址是https://create.kahoot.it/login
这是我正在运行的代码:
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$loginUrl = 'https://create.kahoot.it/login';
//init curl
$ch = curl_init();
//Set URL
curl_setopt($ch, CURLOPT_URL, $loginUrl);
//HTTPS
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//try to echo post variables
var_dump($_POST);
print_r($_POST);
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password);
//Handle cookies
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
// to return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//login
$store = curl_exec($ch);
//put page details in file
file_put_contents("test.txt",$store);
?>
--编辑--
通过将邮递员从 POST 更改为 GET,它返回
{"error":"Authentication failed","exception":"Authentication failed","error_description":"Authentication token of type [class no.mobitroll.core.security.shiro.tokens.SessionToken] could not be authenticated by any configured realms. Please ensure that at least one realm can authenticate these tokens.","timestamp":1499789957919,"duration":0,"errorCode":0}
【问题讨论】:
-
好吧,如果您真的看到了该表单正在做什么(通过您的网络选项卡),当您提交表单时,它会将 POST 请求发送到create.kahoot.it/rest/authenticate,而不是您上面的 URL -那只是包含表单的登录页面。表格不必发回给自己! 405 表示方法不允许,并且鉴于 URL 只是一个表单,因此他们不允许向其发送 POST 是可以理解的。当然不能保证更改 URL 会起作用,他们可能有反欺骗措施,但你只能尝试。
-
我收到了
301 Moved Permanently,但我们正朝着正确的方向前进!不过,我所有的细节仍然是空的 -
通常 301 响应将包含指向资源移动到的位置的链接。例如
HTTP/1.1 301 Moved Permanently Location: http://www.example.org/index.asp。浏览器会自动响应并立即请求新的 URL,但 cURL 不会这样做。您需要提取该位置(每次以编程方式,或手动然后更改脚本以对新 URL 进行硬编码)并 POST 到该位置。 -
请参阅stackoverflow.com/questions/9183178/… 了解从 cURL 获取标头的方法
-
我让它工作了。我需要以
application/json的形式发帖,并且需要第三个字段。
标签: php html post get http-status-code-401