[英]Input URL like http://example.com changes to http:/example.com in action input
I asked a question to get URL as action input here . 我问了一个问题, 在这里将URL作为动作输入。 Now I have a new problem.
现在我遇到了一个新问题。 The passed URL to action changes from
http://example.com
to http:/example.com
. 传递的操作URL从
http://example.com
更改为http:/example.com
。
I want to know why and how can I resolve the problem. 我想知道为什么以及如何解决问题。
PS: I added this code to resolve but I think there may be another problems in future! PS:我添加了这个代码来解决,但我认为将来可能还有其他问题! the code is:
代码是:
if ((url.Contains(":/")) && !(url.Contains("://")))
{
url = url.Replace(":/", "://");
}
use regex: 使用正则表达式:
string src = @"http://example.com";
string result = Regex.Replace(src, @"(?<=https?:/)/", "");
if you need to revert: 如果你需要恢复:
string src = @"http:/example.com";
string result = Regex.Replace(src, @"(?<=https?:)/(?=[^/])", @"//");
The browser (or server) is replacing a double slash (illegal) with a single one. 浏览器(或服务器)正在用一个替换双斜杠(非法)。
Try it, 试试吧,
http://stackoverflow.com/questions/11853025//input-url-like-http-site-com-changes-to-http-site-com-in-action-input
(in Chrome) goes to: (在Chrome中)转到:
http://stackoverflow.com/questions/11853025/input-url-like-http-site-com-changes-to-http-site-com-in-action-input
If I were you, I would remove the http:// from your path and add it later. 如果我是你,我会从您的路径中删除http://并稍后添加。
http://localhost:1619/Utility/PR/example.com/
Then, url = "http://" + url;
然后,
url = "http://" + url;
If you might get secure urls, add that to the route /http/example.com
or /https/example.com
如果您可能获得安全网址,请将其添加到路由
/http/example.com
或/https/example.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.