I have did this several times on Visual Studio C# on Windows.
Now I am using my Mac - creating a Xamarin App in Visual Studio C# and this simple code does not work:
using (HttpClient myClient = new())
{
myClient.DefaultRequestHeaders.Accept.Clear();
myClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await myClient.GetAsync(url);
string result = await response.Content.ReadAsStringAsync();
return result;
}
The url is: "http://webcode.me".
I tried to create a URI, same issue.
What happens is, that when the code line:
HttpResponseMessage response = await myClient.GetAsync(url);
is called, it never returns. And the app never starts.
Of course, the url I am using is just a test url, but after calling this method, my output window looks like this:
2021-04-16 15:40:07.653142+0200 PHC.iOS[3243:87620] Starting Up
Resolved pending breakpoint at 'Main.cs:35,1' to void PHC.iOS.Application.<GetBridges>d__2.MoveNext () [0x000b2].
Resolved pending breakpoint at 'Communicator.cs:44,1' to void PHC.BridgeCommunication.Communicator.<DoGet>d__4.MoveNext () [0x00189].
2021-04-16 15:40:07.664131+0200 PHC.iOS[3243:87620] Now trying URL: http://webcode.me
Resolved pending breakpoint at 'Communicator.cs:58,1' to void PHC.BridgeCommunication.Communicator.<DoGet>d__4.MoveNext () [0x001b9].
Thread started: #2
2021-04-16 15:40:08.249780+0200 PHC.iOS[3243:87661] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=3243
2021-04-16 15:40:08.250077+0200 PHC.iOS[3243:87661] SecTaskCopyDebugDescription: PHC.iOS[3243]/0#-1 LF=0
2021-04-16 15:40:08.259552+0200 PHC.iOS[3243:87661] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
Thread started: #3
Thread started: #4
Thread started: <Thread Pool> #5
Thread started: <Thread Pool> #6
And it continues forever with the Thread starting and Thread stopping information.
The "Starting Up" and "Now trying URL: http://webcode.me" are console output from the class calling this function. After writing these things in the console, the method shown above is called.
I can get things to work on my Windows Visual Studio, with no problems at all.
I am NOT Mac-expert, but I am wondering if my Mac is somehow blocking the call. The firewall is turned off.
Can anyone help me a bit?