简体   繁体   English

将Xamarin Forms应用程序链接到API

[英]Linking a Xamarin Forms app to an API

I have an idea for a project in college. 我有一个大学计划的想法。 The idea is to make a Xamarin app that will find the cheapest flight between an entered date from a select number of airlines for the user. 这样做的想法是制作一个Xamarin应用程序,该应用程序将从用户选择的多家航空公司的输入日期中查找最便宜的航班。 (Just like SkyScanner or Expedia) (就像SkyScanner或Expedia)

I think the best way to do this would be by extracting the data from the airline's API's and comparing the flights that way. 我认为最好的方法是从航空公司的API中提取数据,然后以这种方式比较航班。

What I was wondering is what would be the best way to do this? 我想知道的是什么是最好的方法? I'm proficient in C# and Javascript/Jquery. 我精通C#和Javascript / Jquery。 Any help is welcome. 欢迎任何帮助。

If you are working on C#, then you can do all the work on it. 如果您使用的是C#,则可以完成所有工作。

1) You will need to build a Web API project and build and endpoit to work with. 1)您将需要构建一个Web API项目,并进行构建和使用endpoit。 You have an example of this here: https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api 您在此处有一个示例: https : //docs.microsoft.com/zh-cn/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web- api

Based on what you want to do, you will have to handle the GET request. 根据您要执行的操作,您将必须处理GET请求。 Then you can send the parameters as query parameters on your URI. 然后,您可以将参数作为查询参数发送到URI。 Example: http://localhost/api/values/?datetime=1505766470 示例: http:// localhost / api / values /?datetime = 1505766470

2) You will need to send the actual request from your mobile application. 2)您需要从移动应用程序发送实际请求。 For doing this, you can do something like this: 为此,您可以执行以下操作:

  RestUrl = http://developer.xamarin.com:8081/api/todoitems/
  var uri = new Uri (RestUrl);
  ...
  var response = await client.GetAsync (uri);
  if (response.IsSuccessStatusCode) {
      var content = await response.Content.ReadAsStringAsync ();
      Items = JsonConvert.DeserializeObject <List<TodoItem>> (content);
  }

You have the whole example right here: https://developer.xamarin.com/guides/xamarin-forms/cloud-services/consuming/rest/ 您可以在此处找到完整的示例: https : //developer.xamarin.com/guides/xamarin-forms/cloud-services/consumption/rest/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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