wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
342 stars 130 forks source link

initialization problem #105

Closed dragodj82 closed 6 years ago

dragodj82 commented 6 years ago

Hello, when I try to initialize the library with jwt authentication I always have the same error that is what I report below, someone knows how to help me.

here is the code I use:

  public static async Task Init()
    {
        _client = UtilWs.GetWordPressClient();
        _clientAuth = await UtilWs.GetAuthenticatedWordPressClient();
    }

   public async void LoginAsync()
    {
        try
        {
            await Init();
        }
        catch (Exception ex)
        {
            await DisplayAlert("Eccezione", ex.Message, "ok");
        }

}

ThomasPe commented 6 years ago

How is your UtilWs class calling the WordPressClient? Are you hosting WordPress on Azure / IIS?

dragodj82 commented 6 years ago

These are the two methods I use to call wordpress bees:

public static async Task GetAuthenticatedWordPressClient(AuthMethod method = AuthMethod.JWT) { if (_clientAuth == null) { _clientAuth = new WordPressClient(ApiCredentials.WordPressUri) { AuthMethod = AuthMethod.JWT }; await _clientAuth.RequestJWToken(ApiCredentials.Username, ApiCredentials.Password); }

        return _clientAuth;
    }

    public static WordPressClient GetWordPressClient()
    {
        if (_client == null)
            _client = new WordPressClient(ApiCredentials.WordPressUri);
        return _client;
    }

my wordpress is on a v-hosting with plesk

ThomasPe commented 6 years ago

that look ok. I suspect your server is returning non-valid json. Can you check the server response in fiddler or wireshark to see what the response body looks like?

dragodj82 commented 6 years ago

I receive this error:

406 Not Acceptable

Not Acceptable

Client browser does not accept the MIME type of the requested page.


Web Server at vangelosecondomarco.it
What could be the problem?
dragodj82 commented 6 years ago

if I execute the command with postman it will work correctly. Only when I use the library in my xamarin project gives me this problem.

dragodj82 commented 6 years ago

Hello, I solved, the problem was in the firewall of plesk that did not block requests.