Hi,
I am exposing a REST web service and in which I have a URL parameter and which should not accept special characters. When there is a special character it should give "404 Not Found".
URL : https://{servername}/test/{testid}
--> testid is the URL parameter
I tried using RegExSearch that didn't work for me. Please help!!
Thanks,
Shree
It is from your problem description unclear what you tried and what failed.
Maybe you can share your OML or error message that you got.
Did you use the OnBeforeRequest to implement your logic?
Regards,
Daniel
Please find the attachments. Below is the URL with special characters and the logic I used to restrict. I have used OnResponse as well but didn't work.. Its giving 500 error and error response in HTML.
It is not 100% to tell from the information you shared, but it looks like you validate the input in the method itself, and I believe you should do it in the OnBeforeRequest of the REST API. Also double check (with debugging) that your regex is correct.
Hi Shreelakshmi,
Have you tried using the built-in function EncodeUrl right before passing them to the REST API?
Kind Regards,João
Hi João,
Could you please tell me, If I use EncodeURL how will I check whether in the URL there is a special character or not ?
As you can see on the description of the function on the screenshot I shared and I'm sharing again below, the purpose of this function is to encode the special characters in a way that they are accepted in a URL.
You also have some examples of what this function does.
You just need to apply the EncodeUrl function when passing the parameter to the API, like in the example below:
The solution which I need is to not to accept special characters. When there is a special character in the URL it should give 404 Not Found Status.
What is the rationale behind not accepting special characters?
In any case, you can use a function to remove the diacritics and compare the result to the original string. If they are the same, then there were no diacritics; otherwise they were.
You can remove the accents and diacritics of a string on client-side using Text Normalizer forge component or on server side using the Normalize String forge component.