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

问题描述:

我想将文本转换为WWW格式。VB.Net将文本转换为WWW格式

E.g:@应该%40%%25等等

有细编码器here,但我想这样做在VB.Net。

我需要这个httpwebrequest,我认为它与x-www-form-urlencoded有关。

您可以使用该Uri.EscapeDataString() method

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

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

如果你只想逃避URL的一部分,但仍保留有效成分,如:/= ? &(等等)你会使用Uri.EscapeUriString()

+0

不错,但我想出了我的答案'System.Web.HttpUtility.UrlEncode(my_string)',但你也可以帮助,谢谢! –

+0

@StefanĐorđević:很高兴你找到了自己的解决方案,但实际上应该使用'Uri.EscapeDataString()'与[** RFC3986 **]兼容(http://tools.ietf.org/html/rfc3986 #section-2.1)标准。 'HttpUtility.UrlEncode/-Decode'不会正确地转义空格,因为它将它们变成'+'而不是'%20'。 –

+0

不错,再次感谢你! –