-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Issue with HttpClient and Xamarin Forms #2711
Comments
If you can please upload this as a minimized reproduction (so we have precisely the same code you're using), it would be much appreciated. Can you also clarify if the HttpRequest is still returning a 200 status/the status you would expect for the executed request, and that the problem is strictly that the debug quits? If that is the case, then the issue could potentially lie elsewhere. |
Hi @pauldipietro, No! As mentioned, the httprequest does not produce any sort of status, instead while debugging, it just exits after spewing out logs on thw debug console. If run without debugging, it just exits. Also! I have tried this out without using modernhttpclient-updated nuget and face the same. Thanks. |
@pauldipietro In the demo project after retrieving the posts, the count is not being assigned to the label. That is only happening in the constructor before the request is made to get the posts. Try changing your method to read like this. As a side note method with an async void signature is a bad idea and typically should only be used for an event handler, otherwise it's best to use async Task. |
@Jalroka : You're a Thank you very much. That worked. With regards to the side note, the reason why it was async void is because I was calling it from a constructor. I have seen quite a few articles on that. However now that I am using RelayCommands, I have changed the method signature to async Task and I use the RelayCommand's .Execute(null) method in the constructor of the ViewModel. All works well now. Once again. Thank you very much. |
What worked was what you saw in my comment.
@pauldipietro <https://github.com/pauldipietro> In the demo project after
retrieving the posts, the count is not being assigned to the label. That is
only happening in the constructor before the request is made to get the
posts.
Try changing your method to read like this.
public async void FetchData()
{
HttpRequestService = new RequestService();
Posts = await HttpRequestService.GetAsync<List>("
https://jsonplaceholder.typicode.com/comments", string.Empty);
this.LblMessage.Text = $"We have {Posts.Count} posts";
}
As a side note method with an async void signature is a bad idea and
typically should only be used for an event handler, otherwise it's best to
use async Task.
…On Tue, Dec 18, 2018 at 8:31 AM dbwelch ***@***.***> wrote:
@Jalroka <https://github.com/Jalroka> Having similar issue, you stated
"That worked", can you tell us what that was that worked?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2711 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAg53rq1WSGyj2wKufEQI15efoBBlWC-ks5u6QpMgaJpZM4T_Dyd>
.
|
Description
I'm having issues trying to do a http request using HttpClient and Modernhttpclient-updated. It worked initially in v2.5.1.527436 but started giving issues in v3+
Steps to Reproduce
public class Comment { public int postId { get; set; } public int id { get; set; } public string name { get; set; } public string email { get; set; } public string body { get; set; } }
client.GetAsync()
.Expected Behavior
It should download the data from the API in JSON format and response should have a StatusCode of 200 Ok if successful or anything else indicating appropriate http errors.
Actual Behavior
The solution just exits debug mode.
Basic Information
Modernhttpclient-updated 2.7.0, Newtonsoft.Json 11.0.2, Latest Xamarin Forms 3.0.0.482510 stable
Nokia 5
Screenshots
Reproduction Link
I have reproduced the error here in this solution
This the output from the Debug Console
Other things tried so far:
The text was updated successfully, but these errors were encountered: