[英]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 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
. 我一直在使用本教程来学习如何从Web
API
发送和检索数据。 However is there another way without using Tasks
and await
? 但是,有没有使用
Tasks
和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? 调用我的web
api
客户端登录的最佳方法是什么? I feel I shouldn't be using await
and async
for this sort of thing but could really use some help. 我觉得我不应该使用
await
和async
这类事情但是真的可以使用一些帮助。
只需从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
,即使在旧版本的.NET
也支持它,你不需要担心任务或线程。 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. HttpClient
还允许您获得结果async
但是您需要提供一个在结果准备好时callback
。
Have a look at http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx 看看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
话虽如此,我同意约翰的评论,你应该使用
await
和async
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.