Reputation: 11
I have URL in the below format, and I want to decode the query string and re-write the URL.
https://api.test.abc.com/parameters?username=%7Busername%7D
How can I decode username using policies and re-write it in the following format:
API Endpoint: /api/affiliated/users/userInfo/?username=abcd.gmail.com
Many thanks in advance.
Upvotes: 0
Views: 1466
Reputation: 11
We cannot directly decode, as there is no option, we have to do delete the first query parameter and rewrite the URI by changing and decoding the query parameter. I used the below code snippet to execute that. (as the question was also to replace the userName in the URL with visibleToUserId along with decoding the value.)
@((Convert.ToBase64String(Encoding.UTF8.GetBytes((string)context.Request.MatchedParameters[\"visibleToUserId\"]))).Replace('=', '~').Replace('+', '-').Replace('/', '_'))Upvotes: 0
Reputation: 221
You can use the System.Net.WebUtility with in the APIM policies
System.Net.WebUtility.UrlDecode(context.Request.Url.Query["username"]
Upvotes: 1
Reputation: 53
You can decode it manually.
context.Request.Url.Query["username"] | Replace:'%7B','{' | Replace:'%7D','}'
Save that username in one variable and use it in rewrite template.
I too want to know some method to decode url in APIM policy.
Upvotes: 0