Search Unity

UnityWebRequest getting 400 A malformed request was made

Discussion in 'Editor & General Support' started by alphadogware, Jul 6, 2019.

  1. alphadogware

    alphadogware

    Joined:
    Nov 15, 2017
    Posts:
    63
    I am trying to convert my ios/android/web page nonunity project to unity so that I can take advantage of the cross-platform advantage unity has and convert 3 code bases to one.

    I can get connected with a UnityWebRequest with my id/pwd. But when I try and send the next web request to pull data from my web service, I get a 400/malformed request. I have compared what is being sent in the nonunity projects to what is being sent in the new test unity project and I can't find a difference, but obviously there is one.

    using (UnityWebRequest webRequest2 = UnityWebRequest.Get(baseUrl + "url removed"))
    {
    webRequest2.chunkedTransfer = true;
    webRequest2.useHttpContinue = false;
    webRequest2.redirectLimit = 128;
    webRequest2.timeout = 60;
    webRequest2.SetRequestHeader("Content-Type", "application/json; charset=utf-8");
    webRequest2.SetRequestHeader("Accept", "application/json");
    webRequest2.SetRequestHeader("Cookie", cookie);
    webRequest2.SetRequestHeader("Authorization", authToken);
    webRequest2.method = "GET";
    yield return webRequest2.SendWebRequest();
    }

    When I throw the url and cookie into PostMan the request works fine and I get the expected body back.

    I've been scouring google trying to find any solution for this issue. Any help at all would be appreciated. I REALLY want to convert this big project over to unity, but I can't if I can't fix this issue.
     
  2. alphadogware

    alphadogware

    Joined:
    Nov 15, 2017
    Posts:
    63
    Update : If I build the unity project out to ios, then I get the expected json code returned. Getting a certificate error if I try and build to android. Will update when fixed.
     
  3. alphadogware

    alphadogware

    Joined:
    Nov 15, 2017
    Posts:
    63
    Update : lol. My cert error was because the date on my android device was set to year 2012. I now get the expected json code returned in ios AND android.

    Any ideas why I get Bad Request from the editor, but it works on mobile device?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,212
    Try with chunkedTransfer set to false. If that doesn't help, use some HTTP debugging proxy (i.e. Fiddler) to examine the traffic.
     
  5. alphadogware

    alphadogware

    Joined:
    Nov 15, 2017
    Posts:
    63
    Thanks for the reply. I tried both values of chunked transfer, but no difference. I will look into Fiddler. Thanks again.