A problem while making a request for API in maui .net
i try to do request to my api But the application stops
I do not get any specific error, but the application stops at the request point and does not receive any response
Why ?
Does it have anything to do with await async
10 Replies
If i try to run it without debug it will become like this
with console applcation working but with maui no
idk why
so a few things I want to point out first:
1) dont use newtonsoft, its slow, old and only used these days for edge cases, .net already comes with a json serializer/deserializer out of the box System.Text.Json
2) dont use RestSharp its not good, just use httpclient
3) have you configured your maui to accept cleartext?
4) Have you added to your csproj to
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
because its complaining of missing files in your output
$mauiapihttpHow to access WEB API without dev tunnels in MAUI?
To enable
UsesCleartextTraffic
you open the file Platforms\Android\MainApplication.cs
and add the following lines replacing the current [Application]
⠀ ⠀
In your asp.net API you would have to do no changes if you're running a emulator in the same machine, if you are using usb, you would have to add to your appsettings.Development.json
the following change:
Change 5213 to the actual port your API uses.TeBeCo
* manually serializing string : bad
* manually deserializing string then object : bad
* leaking UTF8 in Service: bad
* leaking mimetype in Service: bad
* not using the httpclient from the service: bad
* create a single httpclient per post request : bad
* create a class named PostRequest to only do a single post, bad
* doing the check of internet inside the post request: bad (way too late)
* using
.Result
while you're in an async methid, bad
* manipulating StringContent
manually badQuoted by
<@1102729783969861782> from #mobile (click here)
React with ❌ to remove this embed.
I'd recommend leowest's suggestions. The cleartext one anyway, as that can cause requests to fail.
My assumption of the issue here is that your android emulator is probably not serving HTTP content locally on port 5117 like your PC is. If you inspect the
request
object, I'd be interested to see why it failed. If you get a HTTP status code, then you know at least it is hitting the HTTP server@TeBeCo @leowest @Auger Thank you guys you have already fixed the problem
If you have no further questions, please use /close to mark the forum thread as answered
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
agreed