Problems uploading screenshot via UnityWebRequest

I’ve been able to find a few other threads similar to this, but none seem able to fix my particular issue. We are uploading a screenshot to our site using the method outlined in the docs. It works in most ways when we use our free server (doesn’t work with WebGL), but to avoid cross-domain errors, we need to move it to our own paid server.

On our paid server it generates a 500 error because mod_security is rejecting it: “Multipart request body failed strict validation: PE 0, BQ 1, BW 0, DB 1, DA 0, HF 0, LF 0, SM 0, IQ 0, IP 0, IH 0, FL 0”]

The parts its failing there are BQ %{MULTIPART_BOUNDARY_QUOTED} and DB %{MULTIPART_DATA_BEFORE}

In this thread I found a possible clue, but no explanation about how to work around it:

Code

    IEnumerator Upload()
    {
        // We should only read the screen buffer after rendering is complete
        yield return new WaitForEndOfFrame();

        // Create a texture the size of the screen, RGB24 format
        int width = Screen.width;
        int height = Screen.height;
        Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

        // Encode texture into PNG
        byte[] bytes = tex.EncodeToPNG();
        Object.Destroy(tex);

        WWWForm form = new WWWForm();
        form.AddBinaryData("file", bytes, "screenShot.png", "image/png");
        UnityWebRequest www = UnityWebRequest.Post("https://ourwebsite.com/process.php", form);
        www.chunkedTransfer = false;
        yield return www.SendWebRequest();

        if (www.isNetworkError || www.isHttpError)
        {
            if (www.isNetworkError)
            {
                Debug.Log("Network Error: " + www.error);
            }
            if (www.isHttpError)
            {
                Debug.Log("Http Error: " + www.error);
            }
        }
        else
        {
            Debug.Log("Report successfuly sent: " + www.downloadHandler.text);
        }
    }

Which Unity version (exactly) are you using? The was a bug in the past where we didn’t put the boundaries correctly.
Try running Fiddler or similar and examine the raw request data.

We’re running 2018.3.11f1.

In the end we’ve worked around it by adjusting our server to accommodate the unexpected data format.