miduo_client/Assets/ztest/TestLanguageTrans.cs

80 lines
2.8 KiB
C#

using GameLogic;
using System.Collections;
using System.Collections.Generic;
using System.Security.Policy;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Types;
using UnityEngine.UI;
public class TestLanguageTrans : MonoBehaviour
{
public InputField inputField;
public Text resultText;
private string url = "http://sdk.user.i.027gm.com/game/verify/login";
public string data = "token = MWY5MWhwb2ZZTnFVUlk3NXZrenVLMXJ6M2g5SEtZZE9iM3A4TkpBRzllZW5ZUFdHVEwrU1E0ZGVEazFJdjJGaE9rWmJzd20xSEE3N2E1T0sxRUtoR3MxSzdiaHJjYXVFS0xxV0QrUmxMNHFmT1AwdUEyM0hSUjZr & appId = 2f89c8ab1866fbd990006df560e887ba&sign=0947f993b7d87d0eb24bdda98f1b8a1b&";
public void OnClick()
{
//LanguageTrans.Instance.TransLanguage(inputField.text, ShowResult);
StartCoroutine(Post());
}
void ShowResult(string r)
{
resultText.text = r;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
IEnumerator Post()
{
//Dictionary<string, string> header = new Dictionary<string, string>();
//header.Add("Content-Type", "application/json");
//header.Add("charset", "utf-8");
//Debug.LogError("data==" + data);
//Debug.LogError("utf8==" + Encoding.UTF8.GetBytes(data));
//byte[] b = Encoding.UTF8.GetBytes(data);
//for (int i = 0; i < b.Length; i++)
//{
// Debug.LogError(b[i]);
//}
//WWW postData = new WWW(url, Encoding.UTF8.GetBytes(data), header);
//while (!postData.isDone)
//{
// yield return new WaitForEndOfFrame();
// //duration += Time.deltaTime;
// //if (duration >= AppConst.HttpTimeout)
// //{
// // XDebug.Log.l(url + " HttpPostError: HttpTimeout:" + AppConst.HttpTimeout + " " + data);
// // if (errorAction != null)
// // errorAction();
// // if (errorLuaFunc != null)
// // errorLuaFunc.Call();
// // postData.Dispose();
// // yield break;
// //}
//}
//Debug.Log(postData.bytes.Length);
//var result = Encoding.UTF8.GetString(postData.bytes);
UnityWebRequest www = new UnityWebRequest(url,UnityWebRequest.kHttpVerbPOST);
DownloadHandler downloadHandler = new DownloadHandlerBuffer();
www.downloadHandler = downloadHandler;
www.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(data));
www.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
yield return www.SendWebRequest();
Debug.Log(www.downloadHandler.text);
Debug.Log(www.downloadHandler.data.Length);
}
}