Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

XSJS and REST API - POST returns 403

$
0
0

Hello All,

 

I'm currently facing a problem with Restfull Api. I use POSTMan from Google Chrome,

 

I am getting error 403 Forbidden when i use POST Method,

I tried with GET and it works fine.

 

Here is my code :

 

function handleGet() {  var output = "Hello World! "  //Open a database connection  var conn = $.db.getConnection();  //Prepare a simple SQL statement on the system table "DUMMY"  var pstmt = conn.prepareStatement("select * from DUMMY");  //Execute the query  var rs = pstmt.executeQuery();  //Check the query result  if (!rs.next()) {     //Something went wrong: Return an error     $.response.setBody("Failed to retrieve data");     $.response.status = $.net.http.INTERNAL_SERVER_ERROR;  } else {     //All went fine: Return the Query result     output = output + "This is the response from my SQL: " + rs.getString(1);  }  //Close the database connection  rs.close();  pstmt.close();  conn.close();  //Return the HTML response.  return output;
}
//Implementation of POST call
function handlePost() {  var bodyStr = $.request.body ? $.request.body.asString() : undefined;  if ( bodyStr === undefined ){  $.response.status = $.net.http.INTERNAL_SERVER_ERROR;  return {"myResult":"Missing BODY"};  }  // Extract body insert data to DB and return results in JSON/other format  var tableName = JSON.parse(bodyStr).table;  $.response.status = $.net.http.CREATED;  return tableName;
}

 

Thanks in advance


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>