对API vv的vv请求
$data = $_POST['csrf'];
$headers = [
"x-csrf-token: $data\r\n".
"Content-Type: application/json\r\n".
"Accept: application/json\r\n"
];
$data = <<<DATA
{
"username": "string",
"password": "string",
"gender": "Unknown",
"birthday": "2021-11-22T23:29:51.656Z",
"isTosAgreementBoxChecked": true,
"email": "string",
"locale": "string",
"assetIds": [
0
],
"bodyColorId": 0,
"bodyTypeScale": 0,
"headScale": 0,
"heightScale": 0,
"widthScale": 0,
"proportionScale": 0,
"referralData": {
"acquisitionTime": "2021-11-22T23:29:51.656Z",
"acquisitionReferrer": "string",
"medium": "string",
"source": "string",
"campaign": "string",
"adGroup": "string",
"keyword": "string",
"matchType": "string",
"sendInfo": true,
"requestSessionId": "string",
"offerId": "string"
},
"agreementIds": [
"string"
],
"identityVerificationResultToken": "string",
"captchaId": "string",
"captchaToken": "string",
"captchaProvider": "string"
}
DATA;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://auth.roblox.com/v1/signup');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}服务器告诉我“错误400,您的浏览器发送了无效的请求”。问题在于x-csrf-令牌,当我将其作为字符串“x token: j8acha7hffh”时,它可以工作。当我将其命名为“:$data”时,它会返回一个错误。我尝试过不同的方法来处理这个错误。我已经改变了标题。尝试了不同的请求方式。还是没有什么能纠正我的错误。我是新的PHP,请帮助!
发布于 2021-11-24 11:37:19
您正在使用$header作为一个array,但是它包含长string,因为我怀疑长字符串中的行分隔符/r/n在这里造成了麻烦。
因此,更改充满新行分隔符的一个值数组。
$headers = [
"x-csrf-token: $data\r\n".
"Content-Type: application/json\r\n".
"Accept: application/json\r\n"
];具有多个值的数组。
$headers = [
"x-csrf-token: $data",
"Content-Type: application/json",
"Accept: application/json",
];CURLOPT_HTTPHEADER格式数组中要设置的header字段数组(“内容-类型:文本/平原”、“内容-长度:100”)
关于https://www.php.net/manual/en/function.curl-setopt.php的更多细节
发布于 2021-11-24 03:32:42
尝试这样做:
“x-csrf-令牌:”.$data.“\r”。
https://stackoverflow.com/questions/70089788
复制相似问题