VB.Net 将文本转换为 WWW 形式

VB.Net Convert text to WWW form

我想将文本转换为 WWW 形式。

例如:@ 应该是 %40% 应该是 %25 等等...

有很好的编码器 here,但我想在 VB.Net 中完成。

我需要这个用于 httpwebrequest,我认为它与 x-www-form-urlencoded.[=16 有关=]

您可以为此使用 Uri.EscapeDataString() method

Dim OriginalURL As String = "http://www.example.com/some file with spaces.php?q1=plus+&q2=at@&q3=svenska språkets 'ö'"
Dim EncodedURL As String = Uri.EscapeDataString(OriginalURL)

在线测试: https://ideone.com/h5fqm1

如果您只想转义 URL 的一部分,但仍保留有效的组件,例如 : / = ? & (等),您可以使用 Uri.EscapeUriString().