Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question UnityWebRequest VS HTTPClient

Discussion in 'Scripting' started by sebascore, Jul 5, 2022.

  1. sebascore

    sebascore

    Joined:
    Apr 27, 2022
    Posts:
    19
    Hi,

    HTTPClient seems to work with a windows IL2CPP client using Unity 2021.3. However, I didn't have the chance to test it with IOS/Android clients.

    Is UnityWebRequest the best solution? The only reason I am asking is that, frankly, I don't trust Unity implementations, but if you tell me that UnityWebRequest is solid, I'll switch to it.
     
    Last edited: Jul 5, 2022
    hamza_unity995 likes this.
  2. SteamB23

    SteamB23

    Joined:
    Mar 3, 2014
    Posts:
    1
    As far as I know HttpClient doesn't work in a WebGL environment. (Threads are required for internal operation, the WebGL environment does not support threads.)

    Also, if you're not using async/await support libraries like UniTask, you can write messy code.

    However, it is clear that the .Net BCL API is a bit more robust than the Unity API.

    Decide on the direction of your project. Maybe this is the realm of taste.
     
    Bunny83 likes this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,572
    That's right but not the only reason why the HTTPClient doesn't work in a WebGL build. The class also needs lowlevel socket support which you don't have in a browser. In a browser the UnityWebRequest wraps around the XMLHttpRequest in javascript. Yes, it's true that Unity's implementation has some shortcommings, but generally works fine for most usecases. The advantage is that it is truely cross platform.
     
  4. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    123
    I just learned today that the HttpClient's PATCH method is not working on iOS.
    All is fine with UnityWebRequest.