我如何执行发布请求?

时间:2015-02-07 21:01:34

标签: c# android post unity3d

我正在尝试将我在Unity中创建的Android游戏的帖子请求发送到服务器。当我运行此代码从我的PC(Unity编辑器)发送请求时,它可以工作,我得到“OK”作为回复。

当我在Android平板电脑或手机上安装应用程序时,服务器不会收到客户端电话的请求。是否有可能C#代码无法在Android上正常运行?那可能是什么问题呢?

代码清楚地从PC运行,Android手机/平板电脑可以成功发送REST客户端的POST请求。非常感谢任何帮助!

using UnityEngine;
using System.Collections;
using System;
using System.Net;
using System.Collections.Specialized;

public class ServerConnection : MonoBehaviour {

    // Use this for initialization
    void Start () {
        using (WebClient client = new WebClient())
        {

            byte[] response =
                client.UploadValues("http://192.168.44.83:12345/keyword", new NameValueCollection()
                                    {
                    { "keyword", "onion" }
                });

            string result = System.Text.Encoding.UTF8.GetString(response);

            Debug.Log (result);
strong text     }
    }

    // Update is called once per frame
    void Update () {

    }
}

0 个答案:

没有答案
相关问题