如何在C#中的URL编码字符串 [英] How to URL encode strings in C#

查看:165
本文介绍了如何在C#中的URL编码字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使用C#中的URL(RFC 1738)标准对字符串进行编码?

How can we encode a string using the URL (RFC 1738) standard in C#?

以下在线工具使用此标准转换字符串 http://www.freeformatter.com/url-encoder.html

The following online tool is converting the strings using this standard http://www.freeformatter.com/url-encoder.html

我要转换的字符串的一个例子是 test(bracket),编码的字符串应如下所示:

An example of the string I want to convert is test(brackets) and the encoded string should look like:

test%28brackets%29


推荐答案

根据 RFC 1738


Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.


两个 HttpUtility.UrlEncode 也不href =http://msdn.microsoft.com/en-US/library/4fkewx0t%28v=vs.110%29.aspx =nofollow> WebUtility.UrlEncode 将对这些字符进行编码,因为标准说括号()可以使用未编码的。

Neither HttpUtility.UrlEncode nor WebUtility.UrlEncode will encode those characters since the standard says the parentheses () can be used unencoded.

我不知道为什么链接的 URL编码器/解码器会编码它们,因为它也列出它们作为可以在URL中使用的字符。

I don't know why the URL Encoder / Decoder you linked encodes them since it also lists them as as a character that can be used in a URL.

这篇关于如何在C#中的URL编码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆