1

我正在尝试通过我的应用程序中的 Sakai LMS 播放 Scorm 内容。为此,我想在登录 Sakai 后获取用户会话并将其传递给任何其他调用。我可以通过休息调用从 Sakai 登录后获取用户会话 cookie,但我无法在标题中传递“Set-cookie”或手动存储 cookie,以便我能够使用它们来调用播放 Scorm 或为当前用户调用其他功能的其他 URL。如何使用 getSession API 返回的 cookie 为登录用户执行其他功能?

我尝试从登录中传递响应标头以进行下一个 API 调用。

我已经尝试形成会话并将其添加到标题后删除“仅 HTML”,如 "SAKAI2SESSIONID="+session+".domain; Path=/;"

我尝试在响应中传递会话 id 和 cookie 并将其手动存储在本地存储中

--1--------

HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse response = client.execute(httpPost);
            Header[] headers = response.getAllHeaders();
            String session=EntityUtils.toString(response.getEntity());
response.setHeader("Set-Cookie","SAKAI2SESSIONID="+session);

----3----

function getSessionId() {
                let data = {
                    password: "pass",
                    userId: "user"
                }
                fetch('http:ldomain/sakai/getSession', {
                    method: 'POST',
                    body: JSON.stringify(data), 
                    headers:{
                        'Content-Type': 'application/json',
                        "Access-Control-Allow-Origin": "*"
                    },

                })
                .then(response => response.json())
                .then(response => {
                    localStorage.setItem('SAKAI2SESSIONID', response.entity.cookie[0])
                    document.cookie= response.entity.cookie[0];
                })
                .catch(error => console.error('Error:', error))
            }         

即使我在执行此操作后尝试点击 Scorm URL 时尝试了所有这些,它也会再次将我重定向到登录页面。

4

0 回答 0