c# - Restsharp returns 403 while Postman returns 200 -


this (modified) snippet postman gives successful call page.

var client = new restclient("http://sub.example.com/wp-json/wp/v2/users/me"); var request = new restrequest(method.get); request.addheader("authorization", "basic anvyytp3mmzacmo2egtbohjsrwrt"); irestresponse response = client.execute(request); 

but when placed in c# app returns 403 forbidden, while postman makes , recieves 200. same thing happens when use httpclient in app (403).

use restclient.authenticator instead:

var client = new restclient("http://sub.example.com/wp-json/wp/v2/users/me") {        authenticator = new httpbasicauthenticator("user", "pass"); };  var request = new restrequest(method.get); irestresponse response = client.execute(request); 

edit:

since issue (as mentioned in comments) fact restsharp doesn't flow authentication through redirects, i'd suggest going combination of httpclient httpclienthandler set authentication flow.


Comments

Popular posts from this blog

renaming files in a directory using python or R -

c# - ajax - How to receive data both html and json from server? -