В настоящее время мне нужно проверить, что пользователи запустили 2 процесса. Это первое. Если возвращается действительный токен, я перехожу к этапу 2, который просто вытягивает список клиентов, а затем сопоставляет имя пользователя. Чтобы получить идентификатор клиента, а затем сохранить его в локальном хранилище, чтобы сохранить пользователя и разрешить более простую отправку заказов
Ошибка: обнаружен непредвиденный символ при синтаксическом анализе значения: ‹. Путь '', строка 0, позиция 0.'
Ошибка расплывчата, как ад, и я понятия не имею, в чем проблема.
class WpApiCredentials
{
public static string SiteUri = "http://TheSite.co.za/";
public static string WordPressUri = $"https://public-api.wordpress.com/wp/v2/sites/{SiteUri}/";
public static string Username = "Name";
public static string Password = "password";
}
WpApiCredentials.Username = Usernamelabel.Text;
WpApiCredentials.Password = PasswordLabel.Text;
var client = new WordPressClient(WpApiCredentials.SiteUri);
client.AuthMethod = AuthMethod.JWT;
await client.RequestJWToken(WpApiCredentials.Username, WpApiCredentials.Password);
var isValidToken = await client.IsValidJWToken();
if (isValidToken)
{
await App.Current.MainPage.DisplayAlert("Token Recieved", "Phase 1 is done ", "OK");
Login_Phase2();
}
else
{
await App.Current.MainPage.DisplayAlert("Empty Values", "Token not Found", "OK");
}
Вот что я могу найти в отношении задачи RequestJWToken
[AsyncStateMachine(typeof(<RequestJWToken>d__29))]
public Task RequestJWToken(string Username, string Password);
[Obsolete("Use JWT instead of Basic")]
Basic,
/// <summary>
/// JSON Web Token Authentication method. Need configure your site with this plugin https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/
/// </summary>
JWT
Полная ошибка
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.12-02 14:59:18.531 I/mono-stdout(20452): at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in <2073514815234917a5e8f91b0b239405>:0 12-02 14:59:18.531 I/mono-stdout(20452): at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x0004a] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <2073514815234917a5e8f91b0b239405>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSeriali
12-02 14:59:18.531 I/mono-stdout(20452): at Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in <2073514815234917a5e8f91b0b239405>:0 zerSettings settings) [0x00000] in <2073514815234917a5e8f91b0b239405>:0
at WordPressPCL.Utility.HttpHelper.PostRequest[TClass] (System.String route, System.Net.Http.HttpContent postBody, System.Boolean isAuthRequired) [0x00212] in <5cf5507fc1ef4ced882a5bb2a8a2f7af>:0
at WordPressPCL.WordPressClient.RequestJWToken (System.String Username, System.String Password) [0x000ba] in <5cf5507fc1ef4ced882a5bb2a8a2f7af>:0
at Ecombeta.Views.Login.Login_Phase1 () [0x000a1] in C:\Users\Roy\source\repos\Ecombeta\Ecombeta\Ecombeta\Views\Login.xaml.cs:100
Ссылка репо
https://github.com/wp-net/WordPressPCL/tree/master/WordPressPCL/Client
Найден метод
public async Task RequestJWToken(string Username, string Password)
{
var route = $"{_jwtPath}token";
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("username", Username),
new KeyValuePair<string, string>("password", Password)
});
(JWTUser jwtUser, HttpResponseMessage response) = await _httpHelper.PostRequest<JWTUser>(route, formContent, false).ConfigureAwait(false);
//JWToken = jwtUser?.Token;
_httpHelper.JWToken = jwtUser?.Token;
}