Unity-WWW类”;不能';t连接到主机”;


Unity - WWW class "couldn't connect to host"

经过研究,我决定使用PHP通过Web播放器应用程序发送邮件,因为在这个平台上不能使用System.net.mail。

在php方面,一切都很好,我使用swift mailer和gmail smtp。当文件被托管并且我通过浏览器调用它时,它工作得很好&发送邮件。

我在同一台服务器上托管我的web应用程序,下面是我调用php脚本的C#代码:

public string phpUrl = "http://myAdress/sendMail.php";
    public void SendMail ()
    {
        StartCoroutine(loadPhpMail());
    }
    private IEnumerator loadPhpMail()
    {
        WWW postPhp = new WWW (phpUrl);
        yield return postPhp;
        if (postPhp.error != null)
        {
            Debug.Log("error : "+postPhp.error);
        }
        else
        {
            if (postPhp.text=="true")
            {
                Debug.Log("success");
            }
        }
    }

而"Debug.Log("error:"+postPhp.error);"一行返回"error:无法连接到主机"。

我做了研究工作,但找不到变通办法。我尝试了一些事情,比如在serv中添加跨域策略。

感谢大家阅读本文。再见

您的URL无效(它是相对URL):myAdress/sendMail.php

你需要使用一个像这样的地址(点击链接查看WWW的使用示例),前缀为"http://",完整的URL包括域名:

http://docs.unity3d.com/ScriptReference/WWW.html

通过更改ANSI中crossdomain.xml的编码来解决。与错误消息无关,但已解决。谢谢大家