c# - 任何永久解决方案这个错误“通过 http 下载,请考虑更新到 https”在 Unity 中?
问题描述
尝试将两个不同的文件上传到后端服务器。一个是 .json 文件,另一个是 .worldmap 文件。当我上传时,我在调试中收到此错误“您正在使用通过 http 下载。目前 Unity 将 NSAllowsArbitraryLoads 添加到 Info.plist 以简化过渡,但很快就会被删除。请考虑更新到 https。通用/未知 HTTP 错误“我注意到有时会出现此错误,有时不会出现。从这个链接解决方案中,解决方案是添加 UnityWebRequest。我已经使用了,但是它仍然继续出现。与我的代码、网址或我的代码中的太多 http 调用有关吗?
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 协议(http://
在 URL 的开头)。Apple 强制执行各种随机策略,其中之一是您必须通过 HTTPS(HTTP 的安全版本)进行通信。尝试将您的 URL 更改为 https。如果您要连接的服务器支持它们,那就太好了。否则,您需要通过获取 HTTPS 证书并将其安装在您的服务器上来使服务器对 https 友好(如果它是您的;否则,您就不走运了)。
推荐阅读
- caching - 执行“a=5”时缓存和 DRAM 会发生什么?
- c# - 如何防止旧版本的 C# dll 运行
- python - Python groupby 多索引
- graphql - 如何仅从 Prisma / GraphQL 查询中获取过滤后的数据
- html - 如何在 CSS 中的形状上放置一个按钮?
- javascript - 如何在echarts中显示总和堆栈栏
- sql-server - Azure SQL Managed Instance - Create Credential not supported
- c# - 有没有办法在 C# 中使用全局计时器?一种可用于多种形式的
- azure - List of all Resources in my Azure Subscription + IAM Access Control Credentials
- java - MockMVC - How to check the content of a JWT token in a spring security integration test with org.hamcrest.Matcher