简体   繁体   中英

Sending POST request from Unity WebGL to HTTPS

I am sending a POST request from a HTTPS page to the following URL:

https://example.com/index.php?fc=module&module=mydemomodule&controller=display

This is the code I use:

IEnumerator CaptureScreenshotAndPost()
{
    byte[] imageBytes = screenImage.EncodeToPNG();
    WWWForm form = new WWWForm();
    form.AddField("hello", "yellow");
    form.AddBinaryData("fileToUpload", imageBytes, "screenShot.png", "image/png");
    UnityWebRequest www1 = UnityWebRequest.Post("https://example.com/index.php?fc=module&module=mydemomodule&controller=display", form);

    yield return www1.Send();

    if (www1.isNetworkError || www1.isHttpError)
    {
        Debug.Log(www1.error);
    }
    else
    {
        Debug.Log("Upload completed!");
    }
}

When the code from above executes, the following error is thrown.

Mixed Content: The page at ' https://www.example.com/index.php?fc=module&module= mydemomodule&controller=display ' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ' http://www.example.com/index.php?fc=module&module= mydemomodule&controller=display?fc=module&module= mydemomodule&controller=display '. This request has been blocked; the content must be served over HTTPS.

我的请求是到https://example.com/index.php?fc=module&module=mydemomodule&controller=display ,但是域已重定向到www .example.com,因此它将其重定向到带有www http://www.example.com/index.php?fc=module&module=mydemomodule&controller=displayHTTP页面。 http://www.example.com/index.php?fc=module&module=mydemomodule&controller=display

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM