Giter Club home page Giter Club logo

httpclient's People

Contributors

claytonindustries avatar claytonone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

httpclient's Issues

iPad OS

Hi,
Implementing HTTP client on my app on iOS solved some issues on UnityWebRequest on iOS but it seems to have an issue on iPadOS.
My app is running perfectly on iOS 14.3 (iPhone 12 Pro Max) but trying it on iPadOS 14.2 & 14.3 (iPad Pro 11" 2020) I cannot read my remote file (same path tested on the 2 devices). Strange isn't it ?

My code is the following, always getting the file content on iOS 14.3, never on iPad OS 14.3 where I always go into the 'else' section :

    HttpClient _client = new HttpClient();
       string file2Load = "http://192.168.1.1/myDirectory/myFile.txt";
      Uri remotePath;
        try
        {
            remotePath = new Uri(file2Load);
        }
        catch (UriFormatException e)
        {
             // do something when error occurs
             return;
        }
        _client.Get(remotePath, HttpCompletionOption.AllResponseContent, r =>
        {
                if (r.HasContent)
                {

                    string fileContent = r.ReadAsString();

                    // do something with the content
                }
                else
                {
                   // cannot access the file / file is empty
                    return;
                }

        });

Maybe you could help me on this.
Regards

ObjectDisposedException: The object was used after being disposed.

I have a problem.

I use HttpClient.GetByteArray to download a file, after a moument call HttpClient.Abort().

ObjectDisposedException: The object was used after being disposed.
System.Net.HttpWebResponse.CheckDisposed ()
System.Net.HttpWebResponse.get_StatusDescription ()
(wrapper remoting-invoke-with-check) System.Net.HttpWebResponse:get_StatusDescription ()
CI.HttpClient.Core.HttpBase+c__AnonStorey1`1[System.Byte[]].<>m__0 () (at Assets/HttpClient/HttpActions/HttpBase.cs:366)
CI.HttpClient.Core.Dispatcher.Update () (at Assets/HttpClient/Dispatcher/Dispatcher.cs:23)

I think this is a multithread problem.

See Dispatcher.cs

    public class Dispatcher : MonoBehaviour, IDispatcher
    {
        private static readonly Queue<Action> _queue = new Queue<Action>();
        private static readonly object _lock = new object();

        private void Awake()
        {
            DontDestroyOnLoad(gameObject);
        }

        public void Update()
        {
            lock (_lock)
            {
                while (_queue.Count > 0)
                {
                    _queue.Dequeue().Invoke();
                }
            }
        }

        public void Enqueue(Action action)
        {
            lock (_lock)
            {
                _queue.Enqueue(action);
            }
        }
    }

Enqueue() called in httpThread, Update() called in MainThread.
TimeLine:

httpThread: Enqueue()
MainThread: HttpClient.Abort()
MainThread: Update() //throw ObjectDisposedException

Requests are sent in Unity Player, but not in the final build on iOS

Hi, first of all, great package! However, for some reason it don't seem to work when running the exported build on iOS. In the Unity Player it works just fine and I can see the response in the Console and the uploaded data in the server database. But when I build the project for iOS and then run either directly with my iPhone connected via USB in Xcode or downloaded from TestFlight, it doesn't make any requests at all. No data is being created/modified on the server and there are also no logs on the server even indicating that a connection was attempted.

Here's my code:

public static class NetworkService
{
    private const string ApiUrl = "https://subdomain.mysite.com/api";

    public static void PutSaveData(HttpClient client, string body)
    {
        var content = new StringContent(body, Encoding.UTF8, "application/json");
        
        client.Put(new Uri($"{ApiUrl}/savedata/{PlayerManager.PlayerID}"), content, HttpCompletionOption.AllResponseContent, r =>
        {
            #if UNITY_EDITOR
            Debug.Log(r.ReadAsString());
            #endif
        });
    }
}

I'm not really sure how to even begin to debug this issue. Is there some way I could view or export the output from Debug.Log() or other logging functions from the iOS build (either via cable or Archived and released via TestFlight)? Because right now the only thing I have to go by is the absence of data/activity on the server - other than that I have no idea where exactly the issue might be.

Maybe it's something to do with permissions? Because the app never asked for any permissions whatsoever, so maybe there's some networking permission I first have the user to grant? I checked settings and the only thing besides Siri is Cellular Data and it's checked, but it doesn't seem to matter whether I'm on WiFi or LTE - no request is made either way.

Any help would be much appreciated. Thanks!

About asynchronous network requests

What should I do if I want to wait for a request to execute successfully before continuing to run the following code instead of making a network request asynchronously?
For example, implement the following functions:
image

NullReferenceException on GetString

When in editor (Unity 2017.4.4f1), Standalone platform or Android platform, below code produces a NullReferenceException:

var httpClient = new HttpClient();
httpClient.GetString(new Uri("https://api.github.com/users/mralexgray/repos"), (r) => {});

That should be located in HttpBase.cs, method HandleStringResponseRead :

...
try 
{
    _response = (HttpWebResponse)_request.GetResponse();
}
catch (WebException e)
{
    _response = (HttpWebResponse)e.Response;
}

using (StreamReader streamReader = new StreamReader(_response.GetResponseStream()))
...

with a Null instance of _response returned by _request.GetResponse().

Bug can be reproduced using the following repository (load the scene named MainScene):

HttpClient.cs : UnityException: Internal_CreateGameObject is not allowed to be called from a MonoBehaviour constructor

Hi,

I was wondering why is this still a thing, or maybe there's something that i'm missing about this behavior in the code,
however it does seem like you need to instantiate an object with the dispatcher in line 448:

private void CreateDispatcherGameObject()
{
if (_dispatcher == null)
{
_dispatcher = new GameObject(DISPATCHER_GAMEOBJECT_NAME).AddComponent();
}
}

I've seen this issue also in another google ads plugin, and i'm wondering when will you fix this.
Currently i'm not sure that I need the dispatcher, however I only just bought the package.

at any case I would suggest to fix this like this (this is how I validate my singletons anyway) :

private static IDispatcher i_dispatcher = null;
public static IDispatcher _dispatcher
{
get
{
if (i_dispatcher == null)
{
i_dispatcher = new GameObject().AddComponent();
}

            return i_dispatcher;
        }
    }

Thanks,
Kobi

Does it work on WebGL?

Hi!

I used to work with this library on standalone, but now I test the code in WebGl and there seems to be no callbacks coming from request.
Here is the sample code:
new HttpClient().Get(new Uri("https://github.com"), HttpCompletionOption.AllResponseContent, response => { if (response.IsSuccessStatusCode){ Debug.Log("Success"); } else { Debug.Log("Fail"); } });
I am not getting any single log in WebGL build, although on Standalone and iOS I get logs in console.
What do I miss?

Adding Custom Headers

_client.CustomHeaders.Add(k,v) "Content-Type" fails with "This header must be modified with the appropiate property."

download mp3 file with stream

when I download mp3 file with HttpCompletionOption.StreamResponseContent the output file get about 10kb like fraction of the download using stream or filestream ?
but HttpCompletionOption.AllResponseContent is working good without getting download progress

Stream Response Content not fixed on NETFX_CORE

Fix on HttpBase.cs (done in commit b8885b1, 10 Aug 2017) for method HandleByteArrayResponseRead(Action<HttpResponseMessage<byte[]>>, HttpCompletionOption, int) should be applied also on the NETFX_CORE part, where the issue remains.

Being more precise, currently, rows 244 to 255 are:

byte[] responseData = null;

if (buffer.Length > contentReadThisRound)
{
    responseData = new byte[contentReadThisRound];

    Array.Copy(buffer, responseData, contentReadThisRound);
}
else
{
    responseData = buffer;
}

but they should be:

byte[] responseData = new byte[contentReadThisRound];

Array.Copy(buffer, responseData, contentReadThisRound);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.