How to make Asynchronous call to HTTPS target through JavaScript

Not applicable

Hi,

Based on the value of 'proxy.pathsuffix' I need to invoke HTTPS back end asynchronously to send the JSON Request. I am trying to do so by using a JavaScript Policy.

Along with the payload I need to send the headers also while invoking the HTTPS URL.

I am trying to use httpCilent() but not able to invoke the HTTPS URL.

Please suggest if we can use httpCient() to invoke HTTPS URL. Below is the javascript I have written for this and please suggest as I am not able to make a call.

var jsonRequest = JSON.parse(context.getVariable("jsonRequestMessage"));
var pathSuffix = context.getVariable("proxy.pathsuffix");
if(pathSuffix =="/search"){
var myRequest =newRequest("https://target1host.com/mysearch/search","POST",
{'Header1': context.getVariable("request.header.Header1"),
'Header2':context.getVariable("request.header.Header2"),
'Header3': context.getVariable("request.header.Header3"),
'Header4': context.getVariable("request.header.Header4")},
JSON.stringify(jsonRequest));}
elseif(pathSuffix =="/match"){
var myRequest =newRequest("https://target2host.com/mymatch/match","POST",
{'Header1': context.getVariable("request.header.Header1"),
'Header2':context.getVariable("request.header.Header2"),
'Header3': context.getVariable("request.header.Header3"),
'Header4': context.getVariable("request.header.Header4")},
JSON.stringify(jsonRequest));}
// asynchronous POST for performance reasons 
var myResult = httpClient.send(myRequest);
// Wait for the asynchronous POST request to finish
 myResult.waitForComplete();
// get the response object from the exchange 
var responsePayload = myResult.getResponse().content;
// expose the response as a flow variable 
context.setVariable("MyCalloutResponse",responsePayload); 
0 1 436
1 REPLY 1

Duplicate question by same user. Please refer Not able to do Async call to HTTPS URL using JavaScript Policy question