Skip to Content
avatar image
Former Member

XSJS - Outbound HTTP Request - POST

I try to send a record to HTTP destination (REST services) using POST method. execution of the code takes to else loop and return "No Response: Issue with the Coding Part". Do let me know, if any part mentioned wrong in the code. Appreciate the help

Note: HTTP destination and xsjs file stored in same package

try {

var query = 'SELECT "MATERIALNUMBER","DIVISION","CUST_GRP1" ' + 'FROM \"PVENKATA\".\"MATERIAL_PRICING\" where "MATERIALNUMBER" = \'XXXXX\'';

var conn = $.db.getConnection();

var pstmnt = conn.prepareStatement(query);

var result = pstmnt.executeQuery();

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

var destination = $.net.http.readDestination("pkg-pvenkata.SIAL_XS1", "MATPRICE_CALL");

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

client.request(request, destination);

var response = client.getResponse();

if(response.body){

$.response.setBody(response.body.asString());

}

else {

$.response.setBody( "No Response: Issue with the Coding Part" );

}

$.response.status = response.status;

$.response.contentType = "application/json";

}

catch(x){

$.response.status = 500;

$.response.setBody( e.message );

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;}

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Sep 16, 2014 at 04:53 AM

    Hi,

    You mentioned you tried to send a record to HTTP destination using POST method, unfortunately I did not find this in your code. I'm not sure if you want to send the result with this code line:

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


    If so, you cannot bind the result when you construct the Request object. You need to first parse the result set and then use the method setBody() to bind the record you want to send.


    You can find the API here. JSDoc: Class: Request

    Best regards,

    Wenjun

    Add comment
    10|10000 characters needed characters exceeded