web傳輸轉義
IEnumerator Post()
{
WWWForm form = new WWWForm();
form.AddField(UrlEncode("123 qwe"), UrlEncode("123 sdfsdf"));
form.AddField(UrlEncode("num2"), UrlEncode("sdf 阿斯頓發生單号"));
WWW www = new WWW("http://" + PublicFunc.GetIp() + ":" + m_port + "/", form);
Debug.Log(www.url);
yield return www;
Debug.Log(www.text);
}
public static string UrlEncode(string str)
{
string sb = "";
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
for (int i = 0; i < byStr.Length; i++)
{
if (i == 0)
{
sb += byStr[i].ToString();
}
else
{
sb += "%" + byStr[i].ToString();
}
}
return sb;
}
public static string UrlDecode(string str)
{
string[] chars = Regex.Split(str, "%25", RegexOptions.IgnoreCase);
byte[] b = new byte[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
b[i] = (byte)(int.Parse(chars[i]));
}
//按照指定編碼将位元組數組變為字元串
return System.Text.Encoding.UTF8.GetString(b);
}