【问题标题】:wont allow post request - 405 error不允许发布请求 - 405 错误
【发布时间】: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


【解决方案1】:

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

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

如果您正在请求 HTTPS,请检查

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

405 错误可能适用于未经许可的方法。例如在只允许 POST 时进行 GET 调用,反之亦然。

【讨论】:

  • 在哪里重要
  • 它什么也不返回。我们开始:
  • 在 curl_close($ch); 之前打印;
  • ( [url] =&gt; https://create.kahoot.it/login [content_type] =&gt; [http_code] =&gt; 0 [header_size] =&gt; 0 [request_size] =&gt; 0 [filetime] =&gt; 0 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0 [namelookup_time] =&gt; 0 [connect_time] =&gt; 0 [pretransfer_time] =&gt; 0 [size_upload] =&gt; 0
  • [size_download] =&gt; 0 [speed_download] =&gt; 0 [speed_upload] =&gt; 0 [download_content_length] =&gt; -1 [upload_content_length] =&gt; -1 [starttransfer_time] =&gt; 0 [redirect_time] =&gt; 0 [redirect_url] =&gt; [primary_ip] =&gt; [certinfo] =&gt; Array ( ) [primary_port] =&gt; 0 [local_ip] =&gt; [local_port] =&gt; 0 )
猜你喜欢
  • 2020-12-13
  • 2021-09-11
  • 2015-08-25
  • 2020-04-29
  • 2019-07-29
  • 2020-03-05
  • 2012-01-04
  • 2018-02-28
  • 2013-10-10
相关资源
最近更新 更多