码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D携带Header发送POST请求

时间:2018-03-12 17:00:18      阅读:2209      评论:0      收藏:0      [点我收藏+]

标签:std   localhost   local   type   bubuko   .text   lib   分享图片   ext   

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请求

标签:std   localhost   local   type   bubuko   .text   lib   分享图片   ext   

原文地址:https://www.cnblogs.com/maskaut/p/8549361.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!