Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by DougInScotland · Aug 24, 2016 at 04:58 AM · networkwebgl

WebGL UnityWebRequest.Post in Firefox returning null from web service

Hi all

I have a web API service with a POST endpoint:

http://mobileappsapi.azurewebsites.net/api/Leaderboards/GetTopThreeLeaderboardItem/

It takes a x-www-form-urlencoded body element "ClientID" with a value of 0.

This works fine in Postman.

I have a game here: http://mobileappsapi.azurewebsites.net/unity/santasaveschristmas/

There is a leaderboard at the bottom left of the start screen which is fed by a UnityWebRequest.Post request to the endpoint.

This works in Chrome, but in Firefox the response showing from the POST to the endpoint in Firebug is null.

If I "resend" the request in Firebug it returns valid request data as JSON as it should do. So I guess there is something in the way that Unity is actually making the call.

Here is the C# method that calls the DoHttpPostRequest method to return the C# LeaderboardItemList object:

 public IEnumerator GetTopThreeLeaderboardItems(System.Action<LeaderboardItemList> result)
     {
         string DataUrl = string.Format("{0}Leaderboards/GetTopThreeLeaderboardItem/", GameStartController.APIUrl);
         string resultString = "";
 
         WWWForm PostData = new WWWForm();
         PostData.AddField("ClientID", GameStartController.ClientID);
 
         yield return StartCoroutine(DoHttpPostRequest(DataUrl, PostData, value => resultString = value));
 
         LeaderboardItemList rs = JsonUtility.FromJson<LeaderboardItemList>(resultString);
 
         result(rs);
     }

Here is the C# DoHttpPostRequest method in Unity:

 public IEnumerator DoHttpPostRequest(string url, WWWForm PostData, System.Action<string> result)
     {
         UnityWebRequest www = UnityWebRequest.Post(url, PostData);
         yield return www.Send();
         
         if (www.isError)
         {
             Debug.Log(www.error);
         }
         else {
             //Debug.Log("HTTP POST request done SUCCESS.");
             result(www.downloadHandler.text); // Pass retrieved result.
         }
     }

I don't think it's related, but for some reason the .mem file request is returning a 404 in firebug. The mime type in the web.config file is

     <staticContent>
                 <mimeMap fileExtension=".data" mimeType="application/octet-stream" />
                 <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
                 <mimeMap fileExtension=".memgz" mimeType="application/octet-stream" />
                 <mimeMap fileExtension=".datagz" mimeType="application/octet-stream" />
                 <mimeMap fileExtension=".jsgz" mimeType="application/octet-stream" />
 </staticContent>

Any ideas please?

Thank you all very much :)


UPDATE (SOLVED!): It ended up being a really simple issue (as is almost always the case). The Web API written with ASP.NET Web API 2 was returning xml rather than json when the request was from Firefox for some reason.

The solution was just to force the api to only return json. This was achieved by adding the following to the WebApiConfig.cs file

 config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"));

It now works perfectly :) I hope this helps someone else out there.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

80 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WebGL and UNet. Cant seem to get in proper contact with server from browser. 1 Answer

How to capture Camera disconnect in using Webcamtexture for Webgl 1 Answer

Unity says my platformer micro game cannot be shared with webGL because the max size is 100 mb, but I should be able to share it 0 Answers

WebGL displacement shader doesn't work in build 0 Answers

How Can I Export To Win10 From Manjaro Linux? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges