Xamarin表单-通过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.ReadAsStringAsync();
return customers;
}

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

我在网上浏览了一下,但有一些解决方案被否决了。

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

任何指导/文件/代码都是有用的。谢谢

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

相关内容

最新更新