php 如何获取PostFields的CURL当有人使用POST CURL到我的API

bnlyeluc  于 2022-11-21  发布在  PHP
关注(0)|答案(1)|浏览(113)

所以,我想得到JSON数据的关键值(从POSTFIELD)在这里我的卷发后测试

  1. <?php
  2. $u = "asd";
  3. $p = "asd";
  4. $tokens = "asd";
  5. $fields_string = '{ "cvalue":"' . $u . '", "ctype":"username", "password":"' . $p . '", "captchaToken":"' . $tokens . '", "captchaId":"", "captchaProvider":"PROVIDER_ARKOSE_LABS" }';
  6. $ch2 = curl_init();
  7. curl_setopt($ch2, CURLOPT_URL, 'https://www-robloxa.com/dd.php');
  8. curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt($ch2, CURLOPT_POST, 1);
  10. curl_setopt($ch2, CURLOPT_POSTFIELDS, $fields_string);
  11. $headers = array();
  12. $headers[] = 'Content-Type: application/json';
  13. $headers[] = 'Accept: application/json';
  14. $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36';
  15. $headers[] = 'Referer: https://www.roblox.com/login';
  16. $headers[] = 'Origin: https://www.roblox.com';
  17. curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
  18. $output = curl_exec($ch2);
  19. echo $output;
  20. ?>

这里是我的phpapi,当我试图获取json的值时

  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3. echo $_POST['cvalue']
  4. ?>
kzipqqlq

kzipqqlq1#

尝试使用“文件获取内容”:

  1. $entityBody = json_decode(file_get_contents('php://input'), true);
  2. $data = isset($_POST['mainField']) ? $_POST : $entityBody;

相关问题