1、客户端 unity 发送post请求
IEnumerator Post()
{
string url = "http://localhost/tp/public/api/v1/test";
//header data
Dictionary<string, string> header = new Dictionary<string, string>();
header["Content-Type"] = "application/json";
header["charset"] = "utf-8";
header.Add("sign", "test sign");
//post data
JsonData data = new JsonData();
data["test1"] = "457";
data["a"] = "124";
data["f"] = "789";
byte[] postdata = Encoding.UTF8.GetBytes(data.ToJson());
WWW _w = new WWW(url, postdata , header);
yield return _w;
Debug.Log(_w.text);
}
//返回值 post data
array(3) {
["test1"] =string(3) "457"
["a"] =string(3) "124"
["f"] =string(3) "789"}
//返回值 header data
array(9) {
["host"] =string(9) "localhost"
["user-agent"] =string(64) "UnityPlayer/2017.2.0f3 (UnityWebRequest/1.0, libcurl/7.51.0-DEV)"
["accept"] =string(3) "*/*"
["accept-encoding"] =string(8) "identity"
["content-type"] =string(16) "application/json"
["charset"] =string(5) "utf-8"
["sign"] =string(9) "test sign"
["x-unity-version"] =string(10) "2017.2.0f3"
["content-length"] =string(2) "35"}
2、服务端 php 代码