简体   繁体   中英

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 . Now I have a new problem. The passed URL to action changes from http://example.com to 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! 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:

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://localhost:1619/Utility/PR/example.com/

Then, url = "http://" + url;

If you might get secure urls, add that to the route /http/example.com or /https/example.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM