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

Unity5 - WWWForm issues

Discussion in 'Scripting' started by Mufan, Mar 5, 2015.

  1. Mufan

    Mufan

    Joined:
    Aug 11, 2013
    Posts:
    15
    Hi!
    I have simple example for web player.

    Code (CSharp):
    1. public void OnButtonClick() {
    2.   StartCoroutine(Request());
    3. }
    4.  
    5. IEnumerator Request() {
    6.   WWWForm form = new WWWForm();
    7.   form.AddField("param", 0);
    8.  
    9.   WWW www = new WWW("http://www.domain.com/query.php", form);
    10.   yield return www;
    11.  
    12.   Debug.Log(www.error);
    13.   Debug.Log(www.text);
    14. }
    This code worked correctly in 4.6.x (for all browsers). But now there are some issues:
    1. It's ok in Google Chrome
    2. I get an www.error in Firefox: Failed to downloading http://www.domain.com/query.php
    3. There is no www.error in Safari, but PHP-script says that he doesn't receive any POST params.

    If I change request to GET params, it's all ok:
    Code (CSharp):
    1. WWW www = new WWW("http://www.domain.com/query.php?param=0");
    What's wrong with POST?

    Thanks!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Struggled good few hours on that couple weeks ago,
    POST worked fine in editor, but not in the webplayer..

    Solution was to set WWWForm.headers, there was example in forums or answers somewhere..
     
  3. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    I have the same problem. What informations shall be set in the header?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    i had this:
    Code (CSharp):
    1. var headers = form.headers;
    2. headers["Content-Type"] = "application/x-www-form-urlencoded";
    then its used at:
    Code (CSharp):
    1. WWW www = new WWW(url,form.data,headers);
     
  5. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    Unfortunately this didn't fix my problem. :-(
     
  6. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    Add one binary field to your WWWForm:
    Code (JavaScript):
    1. wwwForm.AddBinaryData("binary", new byte[1]);
    Now everything should work.