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

WWW class seems to be partially broken

Discussion in 'Editor & General Support' started by MegadethRocks, Sep 17, 2014.

  1. MegadethRocks

    MegadethRocks

    Joined:
    Dec 12, 2009
    Posts:
    162
    I'm using the WWW class to send some Post data back to our servers (saved game file). This has seemed to be working well for a year or so, but this week we've had 4 different school districts who can't save any more.

    Digging into the issue a little more, it is happening only on Macs (so far) running from 10.6.9 to 10.9.4. It either always has the problem or always doesn't, depending on the Mac. Ours work fine, as do a lot of customers, while there are some districts where none of their computers work (in schools, almost all computers have identical specs).

    The headers appear to be getting mangled when they are sent to our server. Basically, the first field of the form gets messed up. It is adding all of the Post command stuff to the beginning of the first field. Then, when it sends the input length, it is off by however many extra characters it added to the first field. This results in the saved game info having the last 200-300 characters chopped off. I'm using the WWW class where you pass a WWWForm in for the data. I was able to hack around this by adding extra characters of junk to the end of the form, but I'd like to know if there is a real solution. Here is the code I'm using to generate the form and send up the data.

    My Code:
    Code (CSharp):
    1. WWWForm form = new WWWForm();
    2. form.AddField("GAction", actionCommand);
    3. form.AddField("gID", ID);
    4. form.AddField("appid", productName);
    5. form.AddField("gData", newGameData);
    6. #if UNITY_STANDALONE_OSX
    7. form.AddField("extra", GetRandomString(1000)); // This hacks around the issue on Macs
    8. #endif
    9. WWW www = newWWW("http://www.mycompany.com/Saving/SaveHandler.php", form);
    10. yield return www;
    And here is what the server is receiving as the post data:
    (Correct, sent from our working Mac)
    [GAction] => SetGData3
    [gID] => BBExt0d2c2416985d4c81fdcfec17e83f1d8b
    [appid] => addition
    [gData] => {1793 characters long (complete data)}​

    (Broken First Field) (^M is how Vim is displaying the CR at the end of each line)
    [POST_/Saving/SaveHandler_php_HTTP/1_1^M
    User-Agent:_UnityPlayer/4_2_2f1_(http://unity3d_com)^M
    Host:_www_mycompany_com^M
    Accept:_*/*^M
    Content-Length:_1954^M
    Content-Type:_application/x-www-form-urlencoded^M
    Expect:_100-continue^M
    ^M
    GAction] => SetGData3
    [gID] => BBExt0d2c2416985d4c81fdcfec17e83f1d8b
    [appid] => addition
    [gData] => {around 1600 characters long (missing data)}​

    Right now we are using 4.2.2, but we could upgrade if there is a good possibility of fixing the issue. For now my best guess is that an underlying library on OSX is being called and it's not working correctly unless that library has been updated.

    Anyway, has anyone seen anything like this before? If it is just a library issue, does anyone know what would need to be updated to make the Macs work?
     
  2. MegadethRocks

    MegadethRocks

    Joined:
    Dec 12, 2009
    Posts:
    162
    No takers, eh? I figured this would be more of a Unity developer issue anyway.

    If it happens to anyone else, I fixed it by adding an extra field with a bunch of fake data at the end. Then you need to add another field (which can be empty) to the beginning, because the first field gets trashed. Or you can just parse through the first field and fix it on the server instead of adding an extra field to the beginning.