Search Unity

WWW.Addbinarydata error 417

Discussion in 'Scripting' started by anshul-bhardwaj, Apr 13, 2015.

  1. anshul-bhardwaj

    anshul-bhardwaj

    Joined:
    Feb 28, 2012
    Posts:
    34
    I am trying to send some data to the server using www class.

    I am using the following code as also given in http://docs.unity3d.com/ScriptReference/WWWForm.html and given below:

    Code (CSharp):
    1.  
    2.     IEnumerator UploadPNG() {
    3.         // We should only read the screen after all rendering is complete
    4.         yield return new WaitForEndOfFrame();
    5.  
    6.         // Create a texture the size of the screen, RGB24 format
    7.         int width = Screen.width;
    8.         int height = Screen.height;
    9.         var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
    10.  
    11.         // Read screen contents into the texture
    12.         tex.ReadPixels( new Rect(0, 0, width, height), 0, 0 );
    13.         tex.Apply();
    14.  
    15.         // Encode texture into PNG
    16.         byte[] bytes = tex.EncodeToPNG();
    17.         Destroy( tex );
    18.  
    19.         // Create a Web Form
    20.         WWWForm form = new WWWForm();
    21.         form.AddField("frameCount", Time.frameCount.ToString());
    22.         form.AddBinaryData("fileUpload", bytes, "screenShot.png", "image/png");
    23.  
    24.         // Upload to a cgi script
    25.         WWW w = new WWW(screenShotURL, form);
    26.         yield return w;
    27.         if (!string.IsNullOrEmpty(w.error)) {
    28.             print(w.error);
    29.         }
    30.         else {
    31.             print("Finished Uploading Screenshot");
    32.         }
    33.     }
    34. }
    I am getting an error as Error 417: Expectation Failure.

    When I remove the line form.addbinarydata(), then everything works fine.

    Any suggestion will be of great help.
    Thanks