我正在尝试使用RESTsharp库认证RESTful服务(sabre REST api),但我无法进行身份验证。我正在使用我的客户端ID和密钥。请告诉我如何使用oAuth 2.0认证器进行身份验证。
我已经尝试了这段代码。(sabre正在使用OAuth 2.0身份验证)
public ActionResult Index()
{
var client = new RestClient("https://api.test.sabre.com");
client.Authenticator = new HttpBasicAuthenticator("myclientid", "myclientsecret");
RestRequest request = new RestRequest("/v1/auth/token", Method.POST);
request.AddHeader("Authorization", "Basic " + client);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "client_credentials");
IRestResponse response = client.Execute(request);
var content = response.Content;
ViewBag.R = content;
return View();
}
我得到了这个结果。
{"error":"invalid_client","error_description":"Credentials are missing or the syntax is not correct"}
请告诉我我做错了什么。谢谢。
使用RestSharp和不使用RestSharp运行代码的Fiddler比较快照如下:
使用RestSharp