Skip to Content
0
Aug 15, 2019 at 07:03 AM

How to call HTTPS outbound service with XSJS

153 Views Last edit May 21, 2020 at 03:16 PM 2 rev

Hi Experts,

A problem is driving me mad! Please help.

I am writing a XSJS code on SCP that calling a HTTPS webservice, I create a user provided service like below and reference it in MTA.yaml file.

User provided service configuration:

My service calling code like below:

var dest = $.net.http.readDestination("EXTERNAL_HTTP");
var connection = $.hdb.getConnection();
var client = new $.net.http.Client();
var request = new $.net.http.Request($.net.http.POST,"/14ec30d6-93f8-4e33-851b-7dd3876e38c2/rpc");
request.headers.set("Content-Type", "application/json");
request.headers.set("apikey", "xxxxxxx");
var oBody = {"xxx": "xxx"};
request.setBody(JSON.stringify(oBody));
client.request(request,dest);
var response = client.getResponse();
$.response.status = response.status;
$.response.contentType = "application/json";	
$.response.setBody(response.body.content);

It always return 301 code in testing, but I use the same URI post the same data, it works perfects!the response status code screen shot like below:

Is anything I lost to do? Can anyone figure out please?

Thanks in advance.

Attachments

301-return-code.png (232.6 kB)
external-http.png (121.7 kB)