Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

wwwForm with binary Field as byte array, form parameter issue

Discussion in 'Editor & General Support' started by r3dwolf, Jul 27, 2015.

  1. r3dwolf

    r3dwolf

    Joined:
    Feb 16, 2012
    Posts:
    39
    Hi!
    I've a problem with the WWW class using wwwForm (with a binary field) as byte array (data property).

    I need to send headers with WWW, the only overload constructor that permits it, is
    public WWW(url: string, postData: byte[], headers: Dictionary<string,string>)
    and has the postData parameter as byte array. I converted the wwwForm to byte array using the "data" property.

    If the form doesn't contain binary data all works well but if in the form there is at least one binary field, the server has some problem to read parameters.

    Has anyone encountered this problem and found a solution?


    WWWForm wwwForm = new WWWForm ();
    wwwForm.AddField ("testKey","testValue");
    wwwForm.AddBinaryData ("testKeybinary",new byte[1]); //binary data
    Dictionary<string,string> headers = new Dictionary<string,string>();
    headers.Add("customheader","customheadervalue");
    WWW www = new WWW (baseURL,wwwForm.data,headers);
    yield return www;
    if (www.error!=null) {
    Debug.Log("ERROR: " + www.error + " - " + www.text);
    } else {
    Debug.Log("RESPONSE: " + www.text);
    }
     
  2. Diomede

    Diomede

    Joined:
    Mar 10, 2015
    Posts:
    31
    I have same problem!. There isn't solution?
     
  3. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    I'm having the same problem, using
    Code (CSharp):
    1. wwwForm.AddField("testKey", "value");
    2. wwwForm.AddBinaryData("testKeyData", System.Text.Encoding.UTF8.GetBytes("value"));
    3. WWW www = new WWW(baseURL, wwwForm);
    works as expected, but if i do
    Code (CSharp):
    1. wwwForm.AddField("testKey", "value");
    2. wwwForm.AddBinaryData("testKeyData", System.Text.Encoding.UTF8.GetBytes("value"));
    3. WWW www = new WWW(baseURL, wwwForm.data);
    the server receives both testKeyData and testKey as files(?)
     
  4. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    I reported the bug.
     
  5. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Same problem for me.
    It seem a WWW bug.

    @Graham Dunnett any feedback from unity team? :)
     
  6. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Don't know. What's the bug number from @Steva?
     
  7. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
  8. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Looks pretty good as a bug report. Not completely sure about the need to do something in PHP on a server. Will ask the QA guys to follow up with you.
     
  9. r3dwolf

    r3dwolf

    Joined:
    Feb 16, 2012
    Posts:
    39
  10. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    @Graham Dunnett Is this problem fixed with WebRequest upcoming features in Unity3D 5.2?
     
  11. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Any feedback from Unity team?
     
  12. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Please, any news?
     
  13. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,080