我有 # 符号作为我的 URL 中的参数传递。但它会丢弃# 之后的所有参数值。请建议我解决方案。以下是我的网址
GetConnectiont?
customerID=customer1&activenode=Sv50&parent=server&frame=imHealthCheckFrame&
connectedFrom=healthCheck&username=root&password=anil#1234&fromAskUsrPwd=askPassword
提前致谢
最佳答案
根据此处找到的答案:How to escape Hash character in URL
将#
替换为%23
。
您可以在此处找到所有保留字符的列表:Percent-encoding .
浅谈 JavaScript 编码
"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]
"Escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )" [2]
在您的情况下,您将仅在查询字符串上使用 encodeURIComponent()
来转义所有保留字符。
! %21
# %23
$ %24
& %26
' %27
( %28
) %29
* %2A
+ %2B
, %2C
/ %2F
: %3A
; %3B
= %3D
? %3F
@ %40
[ %5B
] %5D
关于java - 如何转义url中的#符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19787525/