Unity3D移动端HTTP无法访问服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014805591/article/details/82660178

原因:
近期在开发Unity移动端的项目时,发现通过HTTP无法请求服务器(前期在编辑器中访问正常,发布到Android端就 凉凉了)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Post : MonoBehaviour {

    void Start()
    {
        StartCoroutine(getPost());
    }

    IEnumerator getPost()
    {
        WWW www = new WWW("url");
        yield return www;

        if(www.error == null)
        {
            string str = www.text;
            Debug.Log(str);
        }
    }
}

以上为测试代码。。。

解决方法:
1、需要将Unity平台切换为Android端。
2、设置以下属性(将Auto改为Require)
红线框内是属性设置

3、修改Package Name属性
4、发布应用,问题解决!

注:此方法亲测可用,若有疏漏之处,欢迎一起交流!

猜你喜欢

转载自blog.csdn.net/u014805591/article/details/82660178