claytonindustries / httpclient Goto Github PK
View Code? Open in Web Editor NEWHttp Client is a plugin that makes it easy to make HTTP / HTTPS REST calls in Unity games
Home Page: https://www.claytoninds.com/
Http Client is a plugin that makes it easy to make HTTP / HTTPS REST calls in Unity games
Home Page: https://www.claytoninds.com/
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
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
Response message should still be read when a http error status code is returned
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!
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):
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
I need something like session which should contain cookies between requests. Does the library support this feature?
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?
_client.CustomHeaders.Add(k,v) "Content-Type" fails with "This header must be modified with the appropiate property."
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
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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.