Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity Multiplayer Unity WebGL does not Post to Azure Function app: form already read

Discussion in 'Multiplayer' started by Tarrag, Apr 9, 2020.

  1. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    I'm on Unity 2019.3.0f3 or 2019.3.0f5 or 2019.3.9 and Azure Functions V3.

    I can't get the post into variables in the Function app: the Function app throws http 500 with "Unexpected end of Stream, the content may have already been read by another component.". So when webgl project is run on browser, chrome shows 500 internal error; firefox doesn't show the data on console but neither shows the error but you can see http 500 error with Fiddler.

    Project runs on Editor and Postman.

    Function app is now running and publicly available at https://unitywebglbugtest.azurewebsites.net/api/TestBug

    Code (CSharp):
    1. public class Function1
    2.     {
    3.         [FunctionName("TestBug")]
    4.         public async Task<HttpResponseMessage>
    5.  
    6.     TestBug([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
    7.             {
    8.                 string myUsername = Convert.ToString(req.Form["clientusername"]);
    9.                 return new HttpResponseMessage(HttpStatusCode.OK)
    10.                 {
    11.                     Content = new StringContent($"Result: {myUsername}", Encoding.UTF8, "text/plain")
    12.                 };
    13.             }
    14.     }
    Unity Webgl built and hosted project you can run to test: https://webglappbugtest.azurewebsites.net

    Sample Unity webgl submit form:
    Code (CSharp):
    1. List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
    2.     string stringTest = "hello@gmail.com";
    3.     formData.Add(new MultipartFormDataSection("clientusername", stringTest, "text/plain"));
    4.     UnityWebRequest www = UnityWebRequest.Post("https://unitywebglbugtest.azurewebsites.net/api/TestBug", formData);
    5.     Debug.Log("Now sending form " + stringTest);
    6.     yield return www.SendWebRequest();
    7.     string queryResult = www.downloadHandler.text;
    8.     Debug.Log(queryResult);
     
    Last edited: Apr 9, 2020
  2. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    485
    I think that you are affected by this bug here : https://forum.unity.com/threads/mangled-post-requests-with-unitywebrequest-on-2018-4-x.858925/

    Your link https://webglappbugtest.azurewebsites.net/ work perfectly for me and i get :

    Code (CSharp):
    1.  
    2. Now sending form hello@gmail.com
    3. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    4.  
    5. Result: hello@gmail.com
    6. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    7.  
    Try GET instead of POST and i'm 100% sure that your code will work for you (as affected user).

    Unity team do not answer for the bug https://forum.unity.com/threads/mangled-post-requests-with-unitywebrequest-on-2018-4-x.858925 ...........
     
  3. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Thanks a bunch for sharing some light @roka ! It then seems like Azure's system suffers from this issue cos I'm seeing this with both chrome/firefox browsers when the data is sent to azure's functions.

    Unfortunately @Kumo-Kairo 's decompressed/gzip solution doesn't work for me , probably cos i'm on 2019.3 version.

    I'll ask a question in your main thread for this issue to keep things together.

    Cheers!
     
  4. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    485
    It's not your Azure's system that have a problem, it's an issue from your computer/system because your project work perfectly fine for me. Do not ask me why, i don't know.
    Also, if unity patch this bug, nobody will be affected anymore.
     
  5. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    485
  6. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Got'cha @roka thanks a bunch !

    Though I really dislike the idea of having no option but using query params particularly after Zoom's hack cos all can easily see these
     
    Last edited: Apr 10, 2020
  7. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    you're right again @roka , i tested this website on a mac book pro and works just fine. It's on my windows 10 machine it fails.
     
  8. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    This is very weird. Just tested it again today and it works just fine ... I made no changes to it, it just works. Fiddler doesn't show garbage anymore ... no clue :(
     
  9. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    485
    It was not the code your problem , but your system environment , maybe you have updated your windows, web browser ect .... and it do the trick.
     
unityunity