URLEncode類解決URL中文亂碼

2021-06-16 08:25:11 字數 1090 閱讀 3649

在開發中,經常會用到url傳遞中文引數,在接收引數時,會有接收到亂碼情況,我們在專案中通過urlencode來實現轉碼~!

package com.common;

public class urlencode ;

private final static byte val = ;

/** */

/*** 編碼

* * @param s

* @return

*/public static string escape(string s) else if ('a' <= ch && ch <= 'z') else if ('0' <= ch && ch <= '9') else if (ch == '-' || ch == '_' || ch == '.' || ch == '!'

|| ch == '~' || ch == '*' || ch == '\'' || ch == '('

|| ch == ')') else if (ch <= 0x007f) else

} return sbuf.tostring();

} /** */

/*** 解碼 說明:本方法保證 不論引數s是否經過escape()編碼,均能得到正確的「解碼」結果

* * @param s

* @return

*/public static string unescape(string s) else if ('a' <= ch && ch <= 'z') else if ('0' <= ch && ch <= '9') else if (ch == '-' || ch == '_' || ch == '.' || ch == '!'

|| ch == '~' || ch == '*' || ch == '\'' || ch == '('

|| ch == ')') else if (ch == '%') else

} else

i++;

} return sbuf.tostring();

} public static void main(string sss)

}

OC 對 URL 進行 URLEncode 編碼

我們在專案中是使用的 asihttprequest 元件來訪問 url 的,在使用 asiformdatarequest 時發出它其中有乙個方法 nsstring encodeurl nsstring string cfstringconvertnsstringencodingtoencoding ...

flask 解決url總是not found問題

解決的辦法就是改埠,如果會命令列操作的話,也可以殺死5000埠,不過這次以改埠為例子。下面開始演示具體問題及解決流程 encoding utf 8 from flask import flask defindex return index page hello def hello return he...

加密解密Url的類

string querystringkey abcdefgh url傳輸引數加密key string passwordkey hgfedcba password加密key region 公共方法 加密url傳輸的字串 public string encryptquerystring string q...