简体   繁体   中英

Calling a Web API from Windows Forms application

http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client

I have been using this tutorial to learn how to send and retrieve data from a web API . However is there another way without using Tasks and await ? Sometimes my requests are taking a long time to return when others are relatively quick.

Are there any other tutorials that may help? What is the best way to call my web api client to login? I feel I shouldn't be using await and async for this sort of thing but could really use some help.

只需从nuget manager下载microsoft http api库到你的项目并使用httpClient

You could just use HttpClient if you like and it is supported even in older versions of .NET , and you would not need to worry about tasks or threading. HttpClient also allows you to get the result async but you would need to provide a callback to be called when the result is ready.

Have a look at http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx

Having said that, I agree with John comments above that you should use await and async

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM