URL用C#编码 [英] URL encode in C#

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

问题描述

我无法找到正确的方法来用C#对URL进行字符串编码.我想要的是将字符串some string编码为some%20code.使用HttpUtility.URLEncode();方法编码是some+string.

I'm having trouble finding the correct way to URL encode a string in C#. What I want is to encode the string some string to some%20code. Using HttpUtility.URLEncode(); method encode is to some+string.

推荐答案

HttpUtility.UrlEncode does the right thing here.

编码一个URL字符串. UrlEncode方法可用于对整个URL进行编码,包括查询字符串值.

Encodes a URL string. The UrlEncode method can be used to encode the entire URL, including query-string values.

对于URL上的空格,+%20都是正确的.

When it comes to spaces on the URL, a + or %20 are both correct.

另请参见 URL编码空格字符:+或%20?.

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

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