Unity3D携带Header发送POST请求

Posted 眯眼看世界

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3D携带Header发送POST请求相关的知识,希望对你有一定的参考价值。

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 代码

以上是关于Unity3D携带Header发送POST请求的主要内容,如果未能解决你的问题,请参考以下文章

RestTemplate发送请求并携带header信息

vue2.0中axios发送跨域请求的时候如何设置header来携带token

spring restTemplate 发送post请求携带参数和请求头

HttpWebRequest 自定义header,Post发送请求,请求形式是json,坑爹的代码

scrapy携带payload发送post请求

JAVA携带参数(带有参数)直接发送POST请求