use*_*234 55 asp.net gmail html-encode urlencode c#-4.0
下面的URL链接将打开一个新的Google邮件窗口.我遇到的问题是Google用空格替换了电子邮件正文中的所有加号(+).看起来它只发生在+符号上.有关如何解决这个问题的任何建议?(我正在使用ASP.NET网页)
https://mail.google.com/mail?view=cm&tf=0&to=someemail@somedomain.com&su=some subject&body =你好+那里你好
(在正文电子邮件中,"你好+你好那里"将显示为"你好你好那里")
Dar*_*rov 86
该+字符在url中具有特殊含义=>它表示空格.如果您想使用+您需要对其进行URL编码的符号:
body=Hi+there%2bHello+there
Run Code Online (Sandbox Code Playgroud)
以下是如何在.NET中正确生成URL的示例:
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();
Console.WriteLine(uriBuilder.ToString());
Run Code Online (Sandbox Code Playgroud)
结果
小智 9
为了+使用 JavaScript对值进行编码,您可以使用encodeURIComponent函数。
例子:
var url = "+11";
var encoded_url = encodeURIComponent(url);
console.log(encoded_url)Run Code Online (Sandbox Code Playgroud)
只需将其添加到列表中即可:
Uri.EscapeUriString("Hi there+Hello there") // Hi%20there+Hello%20there
Uri.EscapeDataString("Hi there+Hello there") // Hi%20there%2BHello%20there
Run Code Online (Sandbox Code Playgroud)
通常你想使用EscapeDataString哪个才是正确的。
| 归档时间: |
|
| 查看次数: |
75865 次 |
| 最近记录: |