Problem Description: Sometimes we need to encode a whole URL, but if the whole code is direct, the colon will be encoded;
Example: http://192.168.1.85:8080/files/1\\paper\\2015-06-05\\150602 Polymer website Paper submission Bug-20150605164633294.doc This string, if encoded directly, the HTTP link will be invalidated.
Solution: I think of the solution is to use long text in place of the characters that need to be retained, encoded instead of back;
public static string Restoreurl (string url) {
//modifier backslash
url=url.replace ("\ \", "/");
Use long text instead to keep the string
url=url.replace (":", "_*colon*_")
. Replace ("/", "_*slash*_")
. replace ("\ \", "_* Backslash*_ "). Replace ("
"," _*blank*_ "). Replace (
"? "," _*question*_ ")
. Replace (" = "," _*equal*_ ")
. replace (";", "_*semicolon*_");
Encode the
url=encodingutil.urlencode (URL);
Url=url.replace ("_*colon*_", ":"). Replace ("
_*slash*_", "/").
replace ("_*backslash*_", "\ \").
Replace ("_*blank*_", "%20")
. Replace ("_*question*_", "?")
. Replace ("_*equal*_", "=")
. Replace ("_*semicolon*_", ";");
return URL;
}