不允许发布请求 - 405错误

时间:2017-07-11 14:02:55

标签: php html post get http-status-code-401

我找到了一个脚本并对其进行了修改,希望能够返回登录页面的内容。但是,该页面似乎不允许我登录。

使用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);

?>

- 编辑 -

  • 响应标头+认证页面内容 enter image description here

  • 通过将邮递员从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}

1 个答案:

答案 0 :(得分:0)

首先使用此代码并调试您的问题。

$info = curl_getinfo($ch);
print_r( $info );

如果您要申请HTTPS 检查

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

405错误可能是针对不允许的方法。例如仅允许POST时进行GET调用,反之亦然。