首页 > 解决方案 > 带有 Cookie 的 POST 请求 | Python > PHP

问题描述

无法将此 python 代码转换为 PHP,PHP 版本似乎没有发送 cookie。

Python:

      jar = r.cookies.RequestsCookieJar()
      jar.set('.ROBLOSECURITY', cookie, domain='.roblox.com', path='/')
      resp = r.post(url="https://auth.roblox.com/v2/logout", cookies=jar)
      print (resp.content)

我尝试使它成为PHP:

      $ch = curl_init("https://auth.roblox.com/v2/logout");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, TRUE);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array()));
      curl_setopt($ch, CURLOPT_VERBOSE, true);
      curl_setopt($ch, CURLOPT_COOKIE, ".ROBLOSECURITY=" . $cookie);
      $resp = curl_exec($ch);
      print_r ($resp);

PHP 输出:

    HTTP/1.1 401 Unauthorized
    Cache-Control: no-cache
    Pragma: no-cache
    Content-Length: 83
    Content-Type: application/json
    Expires: -1
    X-Frame-Options: SAMEORIGIN
    Roblox-Machine-Id: RP-WEB1004
    P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM 
    PRE"
    Date: Sat, 27 Oct 2018 14:29:39 GMT


{"errors":[{"code":0,"message":"Authorization has been denied for this 
request."}]}

标签: phppython

解决方案


推荐阅读