public string GetAccessToken(RestClientOptions restClientOptions)
{
var Restclient = new RestClient("http://example.com");
restClientOptions.Authenticator = new HttpBasicAuthenticator("Username", "Password");
var request = new RestRequest("/api/v1/Auth", Method.Post);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{ \"grant_type\":\"client_credentials\" }", ParameterType.RequestBody);
var responseJson = Restclient.Execute(request).Content;
var token = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseJson)["access_token"].ToString();
if (token.Length == 0)
{
throw new AuthenticationException("API authentication failed.");
}
return token;
}
输出中抛出错误:方法有非空返回值,但没有预期结果
我期待打印 Accesstoken,还有我如何存储令牌并使用它来测试其余端点?