You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP调用Runescape登录API生成Session Cookie遇200响应问题求助

问题:调用Runescape登录API返回200而非预期302,缺失关键请求字段

我正在编写PHP代码,通过调用Runescape的登录POST API生成并保存session cookie,预期会收到302重定向响应,但实际得到的是200响应。我怀疑问题出在请求负载缺少部分字段,以下是我的PHP代码,以及浏览器网络捕获到的完整请求负载(其中goBackUrl、correlationId、signature等为自动生成字段,我不知如何在代码中填充),恳请帮忙排查问题。

/**
     * Generate a new runescape.com session token
     * @return string - session token, login failed or simply false
     */
    private function get_session_token(){

        $fields_string = "";

        $fields = array(
            'username' => urlencode($this->_pugLogin),
            'password' => urlencode($this->_pugPassword),
            'theme' => urlencode("dual"),
            'ssl' => urlencode("0"),
            'flow' => urlencode("web"),
            'mod' => urlencode("jpp"),
            'dest' => urlencode("community"),
            'rejectOnGoBackRequired' => urlencode("true"),
        );

        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        $fields_string = substr($fields_string, 0, -1);
        $url = "https://secure.runescape.com/m=weblogin/login-submit";
        curl_setopt($this->curl, CURLOPT_URL, $url);
        curl_setopt($this->curl, CURLOPT_HEADER, 1);
        curl_setopt($this->curl, CURLOPT_POST, 1);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($this->curl, CURLOPT_REFERER, "https://secure.runescape.com/m=weblogin/login-submit");
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, array(
            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Encoding: gzip, deflate, br",
        "Accept-Language: en-GB,en-US;q=0.8,en;q=0.6",
        "Cache-Control  max-age=0",
        "Connection:keep-alive",
        "Content-Type: application/x-www-form-urlencoded",
        "Origin: https://secure.runescape.com",
        "User-Agent:nMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87",
        ));
        $result = curl_exec($this->curl);
        $responseCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
        if($responseCode == 302 && $result){
            $session_index_start = strpos($result, 'session=') + 8;
            $session_index_end = strpos($result, ';', $session_index_start);
            $session_length = $session_index_end - $session_index_start;
            $session_token = substr($result, $session_index_start, $session_length);
            return $session_token;
        }elseif($responseCode == 200){
            return 'login failed';
        }else{
            return false;
        }
    }

浏览器捕获的请求负载:

username: testy@t.t
password: testing123
theme: dual
flow: web
rejectOnGoBackRequired: true
goBackUrl: https://account.jagex.com/oauth2/auth?response_type=code&client_id=jpp-auth&scope=openid%20user.email.read&state=oOmpHKCisqfPEYCnjd9HlRx1ukxEXqDbdUrV7Bny6dY%3D&redirect_uri=https://auth.runescape.com/jpp-auth/login/oauth2/code/jpp&nonce=__c2lKfApFji8F2NGl2aN8loGu7_Hc2dkjXJe2PKslI&flow=web
correlationId: 41a1877d-654a-4934-88b9-0b167ea63a64::1698280054901
signature: 8B3EC0148A5C6DF53D42B3F3218ECD7C814B0FAA4BA52018056D9FFE9F84E4EBC981946F81035E760F9773A59AC33B1D1B7AECE6EE8B69119D98420C8B768EA1
mod: jpp
dest: 1hoIao2uAVai5BrXvhjicM

内容的提问来源于stack exchange,提问作者Kyle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 23:27:22