NetSuite:如何发送http请求发送cookie?

问题描述 投票:0回答:2

我需要调用外部API来从SuiteScript文件中获取一些数据,而且我遇到了问题。 GET调用需要使用凭证(基本上,它必须与请求标头中的cookie一起使用)。

如果我从chrome控制台设置withCredentials = true进行API调用,但是当我使用NetSuite N / https模块进行API调用 - 通过https.get()-时,cookie不会出现在请求标头上。

总而言之,我正在寻找一种在withCredentials = true调用上设置http.get()的方法,或者能够以某种方式从我的SuiteScript中获取cookie,以便我可以在调用的header选项中手动设置它。

在此先感谢您的时间!

netsuite suitescript suitescript2.0
2个回答
2
投票

在get中,传递headers选项并填充标题值。我相信这些是KVP。


0
投票

如果您的外部应用程序期望有关登录用户的信息,那么您可能想要做的是XHR请求(jQuery的$ .getJSON将是您最好的选择)。如果您需要将信息传递到服务器端脚本,那么您将使用返回的数据调用您的Suitelet。

一个帖子的例子如下。注意withCredentials:

$.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: url,
            dataType: "json",
            data: jsonData,
            xhrFields: {
                withCredentials: true
            },
            success: function(response){
                console.log(response);
            },
            error: function(response){
                console.log('error: ' + JSON.stringify(response));
            }
        });
© www.soinside.com 2019 - 2024. All rights reserved.