7.1 HTTP URL Code編碼 : 以HTTP傳送 message需經URLCode編碼
【JavaScript URLCode 範例】
<script type="text/javascript">
encodeURIComponent('簡訊內容');
</script>
【C# URLCode 範例】
public string UrlEncode(string str)
{
StringBuilder sb = new StringBuilder();
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
for (int i = 0; i < byStr.Length; i++)
{
sb.Append(@"%" + Convert.ToString(byStr[i], 16));
}
return (sb.ToString().ToLower().Replace("%20", "+").Replace("%2d", "-").Replace("%5f", "_"));
}
【PHP URLCode 範例】
function urlencodestr($string)
{
$str = strtolower(urlencode(mb_convert_encoding($string, 'utf-8', 'big5')));
$str = str_replace("%20","+",$str);
$str = str_replace("%2d","-",$str);
$str = str_replace("%5f","_",$str);
return $str;
}
【JSP URLCode 範例】
public String urlEncode(String str)
{
StringBuffer stringBuffer=new StringBuffer();
byte[] byStr=str.getBytes();
for(int i=0;i < byStr.length;i++)
{
stringBuffer.append("%"+byStr[i]);
}
return stringBuffer.toString().toLowerCase().replace("%20", "+").replace("%2d", "-").replace("%5f", "_");
}
|