Xamarin Forms - 通过 API 连接到 Wordpress 的最佳方法
Xamarin Forms - Best Method for Connecting to Wordpress through API
我正在尝试通过用 Xamarin Forms 编写的 iOS 应用程序使用 REST API 连接到我的 Wordpress 网站。
我的工作流程是这样的:
用户在应用程序的登录屏幕中输入用户名和密码。
该代码将连接到我的 wordpress 网站,以查看用户名/密码是否与 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.ReadAsStringAsync();
return customers;
}
我想我在身份验证等过程中遗漏了一些东西,因为它不起作用。
我在网上四处查看,但有一些解决方案已被弃用。
成功从 Wordpress 检索用户数据的最佳方法是什么?
任何指导/文档/代码都会有用。谢谢
问题已解决。需要使用JWT Auth插件来帮助验证用户名和密码。
我正在尝试通过用 Xamarin Forms 编写的 iOS 应用程序使用 REST API 连接到我的 Wordpress 网站。
我的工作流程是这样的:
用户在应用程序的登录屏幕中输入用户名和密码。
该代码将连接到我的 wordpress 网站,以查看用户名/密码是否与 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.ReadAsStringAsync();
return customers;
}
我想我在身份验证等过程中遗漏了一些东西,因为它不起作用。
我在网上四处查看,但有一些解决方案已被弃用。
成功从 Wordpress 检索用户数据的最佳方法是什么?
任何指导/文档/代码都会有用。谢谢
问题已解决。需要使用JWT Auth插件来帮助验证用户名和密码。