问题描述
我试图通过我的Xamarin Forms编写的iOS应用程序使用REST API连接到我的WordPress网站。
我的工作流程是这样:
这是我的代码: 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;
}
我认为我在身份验证过程中遗漏了一些东西,因为它不起作用。
我已经在网上四处看看,但是已经淘汰了一些解决方案。
任何指南/文档/代码将很有用。谢谢。
解决方法
解决了该问题。需要使用JWT Auth插件来帮助验证用户名和密码。