php - 带有 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."}]}
解决方案
推荐阅读
- android - 我们如何在 Android Studio 中禁用离线模式?
- mysql - MySql Server 使用最新的 C++ Redistributable 2015-2019 安装问题
- r - 如何创建变量名称及其级别的表?
- visual-studio - CMake项目使用外部SDK工具链文件交叉编译错误
- r - R 在 do.call(rbind) 上设置列名
- c# - C# 我的应用程序在任务管理器中启动但未显示在桌面中
- javascript - ngDestroy 生命周期未在动态创建的 Angular 组件中触发
- swift - 你可以在没有 segue 的情况下更改视图控制器吗?
- ios - 如何在单个tableview中传递多个数据
- laravel - Laravel 在控制器中从另一个类重定向