1. 程式人生 > >Unity3D移動端HTTP無法訪問伺服器

Unity3D移動端HTTP無法訪問伺服器

原因: 近期在開發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、釋出應用,問題解決!

注:此方法親測可用,若有疏漏之處,歡迎一起交流!