cancel
Showing results for 
Search instead for 
Did you mean: 

$.net.http Only error POST in xsjs

0 Kudos

Hi Expert,

I have app xsjs that needs to send to odata Provisioning. I configured a destination and the app can connect with GET method but not POST method.

file.xsjs

var destination_package = "SUPERCL_GAC.xsjslib",
        destination_name = "Test2",
  	dest = $.net.http.readDestination(destination_package, destination_name),
  	client = new $.net.http.Client(),
  	oResult;
  	try {
  	        var req = new $.net.http.Request($.net.http.POST, "/EtArtprovSet");
  		req.headers.set("Content-Type", "application/json");
  		req.headers.set("Accept", "application/json");
  		req.setBody(JSON.stringify(objData));
  		client.request(req, dest);
  		var response = client.getResponse();
                var bodyString = response.body.asString(); 
                return bodyString ;
        } catch (errorObj) {
  		$.response.setBody(JSON.stringify({
  			ERROR: errorObj.message
  		}));
  		return "Error:" + errorObj.message;
  	}

This is only body return.

SergioG_TX
Active Contributor

what error are you getting?

0 Kudos

This it is the problem. Only show me "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\n".

0 Kudos

Hi experts, i'm here again. I can found the problem. My app xsjs needs to conect to oData Provisioning. for some reason, the metod post cann't be get and return code status 403.

0 Kudos

Hi experts,

After many attempts, I found the solution. I had to share destination and client for two calls, first get the X-CSRF-Token and them post oData.

But, now i have a problem whit Post Body. The oData destination cann't process the JSON.

The error show me:

Illegal argument for method call with message

Thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

SergioG_TX
Active Contributor
0 Kudos

if that is the case, then your HANA system is locked down and you may not be able to call services outside your network. i encountered that situation and got it fixed by coordinating with my network team. they had to open some ports on the hana xs to be able to make outbound calls (they will require the destination IP / host so that they can whitelist it) sometimes it may even require you to make the outbound request via a proxy (again.. your network team will have more details on it when you mention you need to make an outbound request from the hana xs engine)

0 Kudos

Thanks Sergio. If Hana system is locked. It can call to method GET ? Because only I have that mistake whit method POST.

SergioG_TX
Active Contributor
0 Kudos

that seems to be a valid response. are you getting an http code other than 200?

you could also test out the destination post/get from a different client such as postman to see if the response is truly getting back to you and figure out if the error is on the destination (response) or on your side. i would approach this situation by checking step by step

0 Kudos

Yes. I'm getting code 403 with POST, but with methot GET is code 200 and show me data.

I don't know that it can be. Do you have any idea ?

SergioG_TX
Active Contributor
0 Kudos

by definition http 403 is forbidden.. so it sounds like the end point does not allow POST on the resource you are trying to consume. do you have the API definiion? you may be able to get the metadata if this is an odata service or the api documentation to see what is the allowed methods on the service/endpoints

0 Kudos

I developed an app Fiori that use this same service odata, now i am trying to implement in xsjs.