3

I had # symbol to pass as parameter in my URL. But it is discarding all the parameter values after #. Kindly suggest me solution. Following is my url

GetConnectiont?   
  customerID=customer1&activenode=Sv50&parent=server&frame=imHealthCheckFrame&
connectedFrom=healthCheck&username=root&password=anil#1234&fromAskUsrPwd=askPassword

Thanks in advance

ANILBABU
  • 297
  • 2
  • 6
  • 21

3 Answers3

10

Per the answer found here: How to escape Hash character in URL

Replace # with %23.

You can find a list of all the reserved characters here: Percent-encoding.


A word on JavaScript encoding

encodeURI(str)

"Assumes that the URI is a complete URI, so does not encode reserved characters that have special meaning in the URI. encodeURI replaces all characters except the following with the appropriate UTF-8 escape sequences:" [1]

encodeURIComponent(str)

"Escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )" [2]

In your case, you would use encodeURIComponent(), only on your query string, to escape any and all reserved chracters.

!  %21 
#  %23 
$  %24 
&  %26 
'  %27 
(  %28 
)  %29 
*  %2A 
+  %2B 
,  %2C 
/  %2F 
:  %3A 
;  %3B 
=  %3D 
?  %3F 
@  %40 
[  %5B 
]  %5D
Community
  • 1
  • 1
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
3

You would need to encode the parameters that may contain # and then decode back the parameter in server side code.

You can use many resources in the internet to URL-encode strings, like this. In your case, anil#1234 becomes anil%231234.

orique
  • 1,295
  • 1
  • 27
  • 36
1

You need to encode the value(if you are using string concatenation to create the url). in javascript you can use encodeURIComponent() like

encodeURIComponent('anil#1234');//or your variable here
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531