Xamarin Forms PCL - clean and easy way for a webrequest?

一个人想着一个人 提交于 2019-12-05 20:25:56

Just use this NuGet package instead https://www.nuget.org/packages/Microsoft.Net.Http PCL http request is implemented in it plus it supports async.

EDIT Sample produly stollen from the Hansleman's web-site.

public static async Task<HttpResponseMessage> GetTheGoodStuff() 
{
    var httpClient = new HttpClient();
    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://hanselman.com/blog/");
    var response = await httpClient.SendAsync(request);
    return response;
}

Flurl.Http (disclaimer: I'm the author) is a Xamarin-compatible PCL that makes this sort of thing really easy:

string s = await "http://www.contoso.com/default.html".GetStringAsync();

Get it on NuGet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!