Search Unity

UnityWebRequest POST issue.

Discussion in 'Scripting' started by Novack, Dec 1, 2015.

  1. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Hi there.
    Im strugling with what looks like an issue on the UnityWebRequest POST method.

    Given a url which is expecting a POST:

    Using a service like www.hurl.it will confirm that works as expected. Allowing to follow redirections, will return the expected data, and switching off redirections, it will return a code 302.

    However, from Unity, no matter what, it returns a code 405. Have tried using the legacy WWWForm and the new List<IMultipartFormSection> for the post data. Have tried redirectLimit on and off (default, or 0). Always 405.

    Any ideas what may be happening?

    Thanks!

    Edit: Tagging @Justinas for reference.
     
    Last edited: Dec 1, 2015
  2. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Forgot to mention that Im working with Unity 5.2.3f1

    [Edit: Also tagging @Alex Lian and @superpig in case this feature still depends of the beta releases context]
     
    Last edited: Dec 3, 2015
  3. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Was trying to inspect the post request that is being sent, but Im not sure how Im supossed to do it. There seems to be no practical way of reading all the headers and body of the request sent. Any ideas?
     
  4. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Oh right, here it is an example server script that works for POST requests, but wont work post requests using the new UnityWebRequest.

    https://script.google.com/macros/s/AKfycbxb10KyfxtIagQSbCl9HFzbFUsIdS9kz9OB4EYwGRLD25WwGro/exec

    Have tried it using http://www.requestmaker.com/ and https://www.hurl.it/. In the first case, it will return an http code 302, and in the second case will return a 302, and a code 200 when enabling to follow redirections. Always as expected.

    However I have not being able to get other than an http code 405 using the new UnityWebRequest api, sending POST resquest with neither the HLAPI or the LLAPI.

    Would you guys have a look at this? Should I report this as a bug instead?
    (Thanks)
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Please report as a bug.
     
  6. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
  7. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    I think I found the issue. It turns out that UnityWebRequest.redirectLimit is not working as expected for UnityWebRequest.Post().

    The docs read about redirectLimit:

    If you wish to disable redirects altogether, set this property to zero.

    However, after doing a POST request, it will follow 302 redirects regardless of UnityWebRequest.redirectLimit = 0;

    Then there is a second problem, UnityWebRequest.Post() asumes redirections maintain the POST method, when it may not be the case. This is the root of my original problem.

    Will replicate this last post on the beta forums.

    [Edit: Bug thread is here.]
     
    Last edited: Dec 3, 2015