Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8538

Re: SAP HANA XS Server - REST Web Services - How to get parameter from URL

$
0
0

Hi Luigi,

 

First there are two mistakes in your .xsjs code.

 

1. $.Response = $.net.http.OK; -> $.response.status = $.net.http.OK;

2. result =  e.toString(); -> var result =  e.toString();

 

Then regarding your problem, first you need to know what the regex "/(\\w+)/(\\d+)/" means. There is a lot of learning materials, e.g. Regular expression - Wikipedia, the free encyclopedia

 

\w means [A-Za-z0-9_]

\d means [0-9]

 

So, in your case, the regex is incorrect. You need to change to the correct one. Don't know if you want to validate the email address and the number in your scenario. I do not validate anything and just use a simple one as "/(.+)/(.+)/"

 

The following is my code and works fine.

 

.xsaccess:

{     "exposed": true,

"default_file" : "post_url.xsjs",

    "authentication": {

    "method": "Basic"    },

        "rewrite_rules" :     [

    {

    "source": "/(.+)/(.+)/",

    "target": "/post_url.xsjs?id=$1&poiid=$2"

    }    ]

}

 

post_url.xsjs:

$.response.contentType = "text/html";

try{

if($.request.method === $.net.http.POST) {

var id = $.request.parameters.get("id");

var poid = $.request.parameters.get("poiid");

var output = id + poid ;

$.response.setBody(output);

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

} catch(e){

var result =  e.toString();

$.response.setBody(output + result);

}

 

 

Best regards,

Wenjun


Viewing all articles
Browse latest Browse all 8538

Trending Articles



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