vv 請求 API 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);
}
http://api.aero-dev.xyz/bin/Captcha/CaptchaId.php?i=2 服務器告訴我“錯誤 400,您的瀏覽器發送了無效請求。” 問題在于 x-csrf-token,當我將它作為字串“x-csrf-token: j8acha7hffh”時,它可以作業。當我把它作為“x-csrf-token: $data”時,它會回傳一個錯誤。我嘗試了不同的方法來解決這個錯誤。我已經更改了標題。嘗試了不同的請求方式。仍然沒有解決我的錯誤。我是 PHP 新手,請幫忙!
uj5u.com熱心網友回復:
您正在使用$headeras anarray但是它包含 longstring因為我懷疑/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 要設定的 HTTP 標頭欄位陣列,格式為 array('Content-type: text/plain', 'Content-length: 100')
https://www.php.net/manual/en/function.curl-setopt.php 中的更多詳細資訊
uj5u.com熱心網友回復:
嘗試這樣做:
"x-csrf-token: ".$data."\r\n"。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/368216.html
