Issue
I'm running the xamarin app on an actual device and receiving Connection Refused
error when making a http request.
Note: the http request works when I use an emulator
I've tried the following as the base Url address: http://127.0.0.1:62597/ , http://localhost:62597/
I've also added Require permission for internet from android manifest. solution-> properties-> Android Manifest tab. However one thing I noticed is that when running the app on the device it is not asking for any permission... I'm quite new to this so any help is much appreciated. Thanks
and this is the StackTrace:
at System.Net.Http.ConnectHelper.ConnectAsync (System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x00180] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs:84
at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ea] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:371
at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync (System.Threading.Tasks.ValueTask`1[TResult] creationTask) [0x000a2] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:529
at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0003f] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:284
at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00070] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RedirectHandler.cs:32
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/HttpClient.cs:506
at Artvertise.Services.RestHelperExtensions.MakeArtPost[TResponseModel] (Artvertise.Services.ArtClient client, System.String route, System.Object data, Artvertise.Services.ContentType contentType) [0x000c5] in C:\Users\agund\source\repos\Artvertise\Artvertise\Services\RestHelperExtensions.cs:82
Solution
the http request works when I use an emulator
This works because the emulator is running on the desktop and use the same network environment with dessktop. When using localhost and not 127.0.0.1, it will find the web server automatically.
However, when running on a physical device, their environment of network are different. You need to specify the IP address of Desktop. Therefore, if using the IP address for emulator, also will work. Such as: https://192.168.1.15:62597/
Solution steps:
First, you need to make sure your desktop and phone are connected to the same WiFi (or any other local network),
Then using your desktop IP address assigned by the router (not localhost and not 127.0.0.1).
How to find out the IP address of your desktop:
- type into the command line
ipconfig
(Windows) - there's going to be a bunch of IP's
- try all of them (except the forementioned localhost and 127.0.0.1)
For example, the following screenshot is my IP adress of my desktop:
Answered By - Junior Jiang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.