如何在URL连接code中的加号(+)符号 [英] How to encode the plus (+) symbol in URL

查看:1418
本文介绍了如何在URL连接code中的加号(+)符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的URL链接会打开一个新的谷歌邮件窗口。我的问题是,谷歌取代所有的加号(+)在电子邮件正文中有空格。它看起来像它只能用+号发生。任何建议如何解决这个问题? (我工作的ASP.NET网页)

The URL link below will open a new Google mail window. The problem I have is that Google replaces all the plus (+) sign in the email body with blank space. It looks like it only happens with the + sign. Any suggestions on how to remedy this? ( I am working the ASP.NET web page)

<一个href=\"https://mail.google.com/mail?view=cm&tf=0&to=someemail@somedomain.com&su=some\">https://mail.google.com/mail?view=cm&tf=0&to=someemail@somedomain.com&su=some受检放大器;机身=您好+你好

https://mail.google.com/mail?view=cm&tf=0&to=someemail@somedomain.com&su=some subject&body=Hi there+Hello there

(在人体中的电子邮件,您好+你好将显示为你好你好)

(In the body email, "Hi there+Hello there" will show up as "Hi there Hello there")

推荐答案

+ 字符在URL中的特殊含义=>这意味着空格。如果你想使用 + 签署需要URL连接code是:

The + character has a special meaning in a url => it means whitespace. If you want to use the + sign you need to URL encode it:

body=Hi+there%2bHello+there

下面是你如何能正确生成.NET的URL的例子:

Here's an example of how you could properly generate urls in .NET:

class Program
{
    static void Main()
    {
        var uriBuilder = new UriBuilder("https://mail.google.com/mail");
        var values = HttpUtility.ParseQueryString(string.Empty);
        values["view"] = "cm";
        values["tf"] = "0";
        values["to"] = "someemail@somedomain.com";
        values["su"] = "some subject";
        values["body"] = "Hi there+Hello there";
        uriBuilder.Query = values.ToString();
        var url = uriBuilder.ToString();
        Console.WriteLine(url);
    }
}

这篇关于如何在URL连接code中的加号(+)符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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