Skip to Content
0

Problem in calling POST Service form XSJS

May 01 at 05:47 AM

127

avatar image
Former Member

Hello All,
I'm trying to call a POST REST API from my xsjs service but I'm getting the following error - HttpClient.getResponse: Can't get the response from the server: no response is pending...you have to issue a request() first

Given below is my destination and xsjs file

http_dest

host = "https://l5471-iflmap.hcisbp.us2.hana.ondemand.com"; pathPrefix = "/http"; port = 467; proxyType = http; proxyHost = "proxy"; proxyPort = 8080; authType = basic; useSSL = false; sslHostCheck = false;

Test.xsjs

try{ var destination; var client;

destination = $.net.http.readDestination("DFT.RulesProject","http_dest");

client = new $.net.http.Client();

var request = new $.net.http.Request($.net.http.POST,"/commonemail");

request.headers.set("Content-Type" , "application/json");

request.headers.set("Accept" , "application/json");

request.setBody(JSON.stringify( { "mailParam":{ "emailBody": "emailBody", "emailSubject": "emailSubject", "to": "shubham.apatidar@incture.com" }}));

client.request(request, destination);

$.response.setBody(JSON.stringify( {

"Success": client.getResponse().status, "Code" : client.getResponse() } ));

}

catch(e){ $.response.status = $.net.http.INTERNAL_SERVER_ERROR; $.response.setBody(e.message ); }

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Thomas Jung
May 01 at 12:49 PM
2

In your host you have HTTPS://. You shouldn't put the protocol there but only the hostname. Also if you have https really as part of the target then why do you have useSSL = false?

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Thomas,

I've changed useSSL= true, imported the certificate, changed the port to 433 and removed the HTTPS:// from hostname. Still I'm getting the below error-

HttpClient.getResponse: Can't get the response from the server: no response is pending...you have to issue a request() first

0

Perhaps the problem is that you are calling getResponse twice:

client.getResponse().status, "Code" : client.getResponse()

I always call this once and put the return object into a variable. Then get the status and body from it.

1
Former Member

Thanks, Thomas.

I'm getting status 401 now.

0

That's progress. I don't see any authentication information in your destination and 401 is unauthorized, so I guess you know where to look next.

0
Former Member

I've given all the authentication credentials in XS Admin and have imported the SSL certificate but still I', facing these issue.

0