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

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -