Xamarin Forms-通过API连接到Wordpress的最佳方法

问题描述

我试图通过我的Xamarin Forms编写的iOS应用程序使用REST API连接到我的WordPress网站

我的工作流程是这样:

  1. 用户在应用程序的登录屏幕上输入其用户名密码

  2. 代码将连接到我的WordPress网站,以查看用户名/密码是否与wordpress中的用户名/密码匹配。

  3. 如果匹配,请转到下一页列出用户详细信息的页面

这是我的代码: XAML

<Label x:Name="Login" Text="Login" TextColor="Black"></Label>

<Entry x:Name="LoginUsername" Placeholder="Username *" PlaceholderColor="Gray" />

<Entry x:Name="LoginPassword" Placeholder="Password *" PlaceholderColor="Gray" IsPassword="True" />

<Button x:Name="LoginButton" Text="Login" BackgroundColor="Green" TextColor="White" Clicked="BtnLoginHandler"></Button>

CS

public async Task<Customers> GetAllCustomers()
        {
            var httpClient = new HttpClient();
            string GetAllCustomersApiUrl = string.Format("{0}/wc-api/v3/customers/4/?consumer_key={1}&consumer_secret={2}",website_url,consumer_key,consumer_secret);
            var response = await httpClient.GetAsync(GetAllCustomersApiUrl);
            HttpContent content = response.Content;
            var json = await content.ReadA@R_404_6455@ringAsync();
            return customers;
        }

我认为我在身份验证过程中遗漏了一些东西,因为它不起作用。

我已经在网上四处看看,但是已经淘汰了一些解决方案。

wordpress成功检索用户数据的最佳方法是什么?

任何指南/文档/代码将很有用。谢谢。

解决方法

解决了该问题。需要使用JWT Auth插件来帮助验证用户名和密码。