How to Include Special Characters in Query Strings

How can I include special characters in query strings?

You have to encode special characters in URLs. See: http://www.w3schools.com/tags/ref_urlencode.asp

How can I consider special character(&) as value in one of the query parameter

Your query parameters should be URL-encoded in order to differenciate a separating & from a random character.

The solution is to encode the value before sending it through the request. You can do so by passing your value to encodeURIComponent(). You can then parse it the same way and decode it using decodeURIComponent(), e. g. :

encodeURIComponent('my&title') -> 'my%26title'
decodeURIComponent('my%26title') -> 'my&title'

How to read query param value if special character (&) part of query param value

If the & character is part of the name or value in the query string then it has to be percent encoded. In the given example: contentName=abc%26def&path=Test&type=folder.

Handling special characters in query string

the # is not included, it's just an indicator for repleaceable content.

Faced a similar mistake with mongodb connect api, when they used to have # in their connection strings.

you can't have an # in the name of a variable/query string, it's just an indicator.

in third party api now, they use <> to mean replaceable content/values
like <access_token=something> or <access_token>.

Query strings with special characters

Use Server.UrlEncode:

URLEncode converts characters as follows:
Spaces ( ) are converted to plus signs (+).
Non-alphanumeric characters are escaped to their hexadecimal representation.

Use it this way;

<a href="page2.asp?name=<%= Server.URLEncode(sName) %>">here</a>


Related Topics



Leave a reply



Submit