php - 是什么导致此代码中出现以下错误:HTTP 错误 411。请求必须分块或具有内容长度?
问题描述
下面的代码位于网络服务器上的 .php 文件中。通过获取请求、group_id、new_role_set_id 和 target_user_id 被发送到网站。然后,该网站登录到另一个网站,在该网站发送获取请求以更改特定组中用户的排名。但是,我得到了这个输出:
You aren't supposed to be here.
Hello!
Length Required
HTTP Error 411. The request must be chunked or have a content length.
代码:
<html>
<head>
<title>Welcome to the promotion bot!</title>
</head>
<body> <h1>You aren't supposed to be here.</h1>
</body>
</html>
<?php
$group_id = $_GET['groupId'];
$new_role_set_id = $_GET['newRoleSetId'];
$target_user_id = $_GET['targetUserId'];
$login_user = 'username=bot&password=bot';
$file_path_rs = 'rs.txt';
$file_path_token = 'token.txt';
$current_rs = file_get_contents($file_path_rs);
$current_token = file_get_contents($file_path_token);
echo "Hello!";
function getRS()
{
global $login_user, $file_path_rs;
$get_cookies = curl_init("https://www.roblox.com/newlogin");
curl_setopt_array($get_cookies,
array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POST => true,
//CURLOPT_HTTPHEADER => array("Content-Length: " . strlen($login_user)),
CURLOPT_POSTFIELDS => $login_user
)
);
$rs = (preg_match('/(\.ROBLOSECURITY=.*?);/', curl_exec($get_cookies), $matches) ? $matches[1] : '');
file_put_contents($file_path_rs, $rs, true);
curl_close($get_cookies);
return $rs;
}
function changeRank($rs, $token)
{
global $group_id, $new_role_set_id, $target_user_id, $file_path_token;
$promote_user = curl_init("http://www.roblox.com/groups/api/change-member-rank?groupId=$group_id&newRoleSetId=$new_role_set_id&targetUserId=$target_user_id");
curl_setopt_array($promote_user,
array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => array("Cookie: $rs", "X-CSRF-TOKEN: $token")
)
);
$resp = curl_exec($promote_user);
$resp_header_size = curl_getinfo($promote_user, CURLINFO_HEADER_SIZE);
$resp_header = substr($resp, 0, $resp_header_size);
$resp_body = substr($resp, $resp_header_size);
if (preg_match('/GuestData/', $resp_header)) {
$resp_body = changeRank( getRS(), $token );
} else if (preg_match('/Token Validation Failed/', $resp_header)) {
$new_token = (preg_match('/X-CSRF-TOKEN: (\S+)/', $resp_header, $matches) ? $matches[1] : '');
file_put_contents($file_path_token, $new_token, true);
$resp_body = changeRank( $rs, $new_token );
}
curl_close($promote_user);
return $resp_body;
}
echo changeRank($current_rs, $current_token);
解决方案
推荐阅读
- c# - 如何指定将被正则表达式替换的位置
- sql-server - 在 .net 核心中添加和使用多个连接字符串
- android - 改造响应总是错误的
- laravel - 是否可以在 Laravel 应用程序中为 Vuejs 提供多个路由条目?
- cypress - 赛普拉斯 - cy.click() 不会点击 select2 下拉列表中的值
- python - 如何在 Python3 中生成随机整数列表
- php - PHP - 生成数组中的所有项目组合
- performance - 调用 canvas.drawImage() 时的性能问题
- objective-c - 崩溃 Xcode 11,iOS13 设置根视图控制器
- c# - 对象在创建时直接初始化(设置值)