Search Unity

Post gif to server throw error: 417 Expectation failed

Discussion in 'Scripting' started by Diablo404, Nov 28, 2014.

  1. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    Hi Everyone,

    Will trying to upload a gif ( yeah, gif ) to my server. I keep getting the 417 Expectation failed error.

    This error is caused because Unity add Expect: 100-Continue in the HTML Header when using WWWForm.

    Sad fact is that header property is ReadOnly so we can't delete it.

    And there is no overload for WWW that allows to pass Form AND Header

    I've tried many things to avoid it but nothing worked.

    .Net got a static method : System.Net.ServicePointManager.Expect100Continue = false;

    But it's obviously not working for WWWForm which is not related to System.Net.

    I mainly tried to copy the header, add the empty Expect and pass the binary datas like:

    Code (CSharp):
    1. postForm.AddBinaryData("theFile",localFile.bytes,localFileName,"image/gif");
    2.  
    3. var headers = postForm.headers;
    4. headers.Add("Expect", "");
    5. WWW upload = new WWW(uploadURL,localFile.bytes, headers );
    The issue is that the php understand that there is something $_POST, but $_FILES is always empty.

    NB: I also tried to implement the System.Net version to upload files ( http://answers.unity3d.com/questions/30895/417-expectation-failed.html ) but didn't manage to get it work.

    NB2: Also tried to modify the header in php with curl:
    Code (CSharp):
    1. <?php
    2.  
    3. // create a new cURL resource
    4. $ch = curl_init();
    5.  
    6. // set URL and other appropriate options
    7. curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
    8.  
    9. // grab URL and pass it to the browser
    10. curl_exec($ch);
    11.  
    12. curl_close($ch);
    13.  
    14. ?>
    Any help on this one will be really apreciated.
     
    Last edited: Nov 28, 2014
  2. anshul-bhardwaj

    anshul-bhardwaj

    Joined:
    Feb 28, 2012
    Posts:
    34
    Hi, I am also facing the same issue, Any success?