此错误的任何永久解决方案“通过http下载,请考虑更新为https".在Unity中? [英] Any permanent solution this error "Download over http ,please consider updating to https" in Unity?

查看:779
本文介绍了此错误的任何永久解决方案“通过http下载,请考虑更新为https".在Unity中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将两个不同的文件上传到后端服务器.一个是.json文件,另一个是.worldmap文件.当我上传时,在调试中出现此错误"您正在使用通过http下载.目前,Unity添加了NSAllowsArbitraryLoads到Info.plist,以简化转换过程,但很快就会删除,请考虑更新为https. 通用/未知的HTTP错误" 我注意到有时会出现此错误,有时不会出现.来自此

Trying to upload two different files into backend server.One is .json file and other is .worldmap file.When I upload I get this error in the debug "You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https. Generic/unknown HTTP error" I have noticed that sometimes this error shows up and sometimes not.From this Link solution the solution is to add UnityWebRequest.I have used that but still it continues to show up.Anything to do with my code ,webaddress or too many http calls from my code?

public void UploadMaps()
{

   StartCoroutine(UploadFileData());
   StartCoroutine(UploadWorldMap());

}
IEnumerator UploadFileData()

{
    string mapnamedl = "pathtest";
    Debug.Log("Mapname local = " + mapnamedl);
    string locapath ="file://" +Application.persistentDataPath + "/" + mapnamedl + ".json";
    Debug.Log("local path = " + locapath);
    WWW localFile = new WWW(locapath);
    yield return localFile;

    if(localFile.error==null)
    {
        Debug.Log("Local file found successfully");

    }

    else
    {
        Debug.Log("Open file error: " + localFile.error);
        yield break; // stop the coroutine here
    }



    Debug.Log("Form bytes = " + BitConverter.ToString(localFile.bytes));




    List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
   formData.Add(new MultipartFormDataSection("Jsondata",localFile.bytes));

    UnityWebRequest www = UnityWebRequest.Post("http://testsite.com/cab/test/save.php",formData);
    yield return www.SendWebRequest();

    if (www.isNetworkError || www.isHttpError)
    {
        Debug.Log(www.error);
    }
    else
    {
        string JSONDATAstring = www.downloadHandler.text;
        Debug.Log("Json String is = " + JSONDATAstring);
        JSONNode JNode = SimpleJSON.JSON.Parse(JSONDATAstring);

        string login = (JNode["upload"][0]["success"]).ToString();

        Debug.Log("login is = " + login);

        if (login == "1")
        {

            Debug.Log("Form upload complete!");

        }
        else if (login == "0")
        {

            Debug.Log("Failed ");

        }


    }
}


IEnumerator UploadWorldMap()
// IEnumerator UploadFileData(string mapnamedl)
{
    string mapnamedl = "pathtest";
    Debug.Log("Mapname local = " + mapnamedl);
    string locapath = "file://" + Application.persistentDataPath + "/" + mapnamedl + ".worldmap";
    Debug.Log("local path = " + locapath);
    WWW localFile = new WWW(locapath);
    yield return localFile;

    if (localFile.error == null)
    {
        Debug.Log("Local file found successfully");

    }

    else
    {
        Debug.Log("Open file error: " + localFile.error);
        yield break; // stop the coroutine here
    }



    Debug.Log("Form bytes = " + BitConverter.ToString(localFile.bytes));




    List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
    formData.Add(new MultipartFormDataSection("Jsondata", localFile.bytes));

    UnityWebRequest www = UnityWebRequest.Post("http://testsite.com/cab/test/save.php", formData);
    yield return www.SendWebRequest();

    if (www.isNetworkError || www.isHttpError)
    {
        Debug.Log(www.error);
    }
    else
    {
        string JSONDATAstring = www.downloadHandler.text;
        Debug.Log("Worldmap String is = " + JSONDATAstring);
        JSONNode JNode = SimpleJSON.JSON.Parse(JSONDATAstring);

        string login = (JNode["upload"][0]["success"]).ToString();

        Debug.Log("Worldmap login is = " + login);

        if (login == "1")
        {

            Debug.Log("Form upload complete!");

        }
        else if (login == "0")
        {

            Debug.Log("Failed ");

        }


    }
}

推荐答案

您正在使用HTTP协议(URL开头的http://). Apple强制执行各种随机策略,其中之一是必须通过HTTPS(HTTP的安全版本)进行通信.尝试将您的URL更改为https.如果您要连接的服务器支持它们,那就太好了.否则,您需要通过获取HTTPS证书并将其安装在服务器上来使服务器对https友好(如果是您自己的服务器,否则,您将很不走运).

You're using the HTTP protocol (the http:// at the beginning of your URL). Apple enforces all kinds of random policies, one of which is that you must communicate over HTTPS, the secure version of HTTP. Try changing your URLs to https. If the server you're connecting to supports them, great. Otherwise, you'll need to make the server https-friendly by getting an HTTPS certificate and installing it on your server (if it's yours; otherwise, you're out of luck).

这篇关于此错误的任何永久解决方案“通过http下载,请考虑更新为https".在Unity中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆