Why does Internet Explorer encode the URL differen

2019-07-19 15:50发布

I'm facing a problem where Internet Explorer (10, but I think I have the same issue with older IEs) will encode a URL differently based on if I click a link normally or if I open it in a new tab by Control-clicking on it.

I have made small JSBin to test the issue, and this is what Wireshark shows when I click the link normally:

Normal click

This is what I get when control-clicking:

Control-click

Notice that the "Å" in the URL is encoded differently, "\305" in the first case, and "\303\205" in the second.

How to reproduce

You need Wireshark or some similar tool, so some work is required.

  1. Go to this JSBin: http://jsbin.com/agukeg/5 in Internet Explorer
  2. Start Wireshark (or your tool of choice) and start capturing.
  3. Click on the link "testme" (normally, not with Control).
  4. Click on the link while holding down Control
  5. Compare the URLs in Wireshark

Why is this happening, and more importantly, is there a workaround or a real fix?

1条回答
迷人小祖宗
2楼-- · 2019-07-19 16:27

That's an invalid URL. Browsers like Google Chrome might fool developers because their address bar show decoded characters, but they never send those characters to server but use standard URL encoding behind the scenes. Additionally, when you copypaste an URL from Google Chrome address bar, the ugly encoding makes it to your clipboard.

The only characters allowed in an URL without encoding are:

Unreserved

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i
j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ . ~

Reserved
Have to be encoded sometimes

! * ' ( ) ; : @ & = + $ , / ? % # [ ]

Encode the URL in your link:

<a href="?pKod=BAS%C3%85R"></a>
查看更多
登录 后发表回答