admin管理员组文章数量:1279021
Visual Studio 2022, installed the .NET Maui toolkit. File -> New Project with .NET Maui Blazor Hybrid App template.
Open up Home.razor and change to the following:
@page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<button @onclick="FetchData">Fetch</button>
<div>@data</div>
@code
{
private string data = "";
private void FetchData()
{
var client = new HttpClient();
var response = client.GetAsync(";).Result;
data = response.Content.ReadAsStringAsync().Result;
}
}
Put a breakpoint on the client.GetAsync
call
Run the app with the android emulator (Pixel 5, API 34).
Click the 'Fetch' button, breakpoint hits in visual studio.
Click "Step Over" in the debug toolbar.
Nothing happens. No error message, no next line, nothing.
I attached with the chrome devtools debugger, and no network call is ever made.
I also tried with an async Task FetchData
method, no difference.
What am I doing wrong here?
---
Edit: I have tried
injecting HttpClient
using an async method with
@onclick="@FetchData"
adding
ConfigureAwait(false)
ensuring the android manifest file has the right permissions (INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE)
setting
android:usesCleartextTraffic=true
calling the FetchData method in
OnAfterRenderAsync
andOnInitializedAsync
using .NET 9
None of these changes did anything - they all behave the same way.
Visual Studio 2022, installed the .NET Maui toolkit. File -> New Project with .NET Maui Blazor Hybrid App template.
Open up Home.razor and change to the following:
@page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<button @onclick="FetchData">Fetch</button>
<div>@data</div>
@code
{
private string data = "";
private void FetchData()
{
var client = new HttpClient();
var response = client.GetAsync("https://httpbin./get").Result;
data = response.Content.ReadAsStringAsync().Result;
}
}
Put a breakpoint on the client.GetAsync
call
Run the app with the android emulator (Pixel 5, API 34).
Click the 'Fetch' button, breakpoint hits in visual studio.
Click "Step Over" in the debug toolbar.
Nothing happens. No error message, no next line, nothing.
I attached with the chrome devtools debugger, and no network call is ever made.
I also tried with an async Task FetchData
method, no difference.
What am I doing wrong here?
---
Edit: I have tried
injecting HttpClient
using an async method with
@onclick="@FetchData"
adding
ConfigureAwait(false)
ensuring the android manifest file has the right permissions (INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE)
setting
android:usesCleartextTraffic=true
calling the FetchData method in
OnAfterRenderAsync
andOnInitializedAsync
using .NET 9
None of these changes did anything - they all behave the same way.
Share Improve this question asked Feb 24 at 14:54 Chad McCallumChad McCallum 211 silver badge2 bronze badges 1 |1 Answer
Reset to default 2After doing even more searching, I tried getting the emulator to reboot (not just saving state and shutting down), and lo and behold that worked. After the emulator restarted, it was able to make API calls over https.
Leaving this here in cause anyone else runs into the same issue.
本文标签: NET Maui on Android Emulator not running httpclientgetasyncStack Overflow
版权声明:本文标题:.NET Maui on Android Emulator not running httpclient.getasync - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741260394a2367507.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
https://httpbin./get does
not appear to be a local link, so no special settings are required on the Android device. For how the Maui program obtains data from the webservice, you can refer to the following official documents and examples. Consume a REST-based web service. – YonglunLiu Commented Feb 25 at 1:29