我通常不會在這裏提問,因爲大部分時間我都可以找到答案。但在這一刻,我沒有找到一個,我真的被卡住了。我有一個問題,試圖獲取Cherwell api的訪問令牌:http://13.88.176.216/CherwellAPI/Swagger/ui/index#!/Service/Service_Token我使用郵遞員生成此代碼:RestSharp Oauth2認證Cherwell restful api
這與Cherwell Service Management的V8 + REST API相關。拋出服務器運行時異常
代碼:
string user = "myUser";
string password = "myPassword";
var client1 = new RestClient("http://13.88.176.216/cherwellapi/token?auth_mode=Internal");
client.Authenticator = new HttpBasicAuthenticator(user, password);
var request1 = new RestRequest(Method.POST);
request1.AddHeader("content-type", "application/x-www-form-urlencoded");
request1.AddHeader("cache-control", "no-cache");
request1.AddParameter("application/x-www-form-urlencoded", "grant_type=password&client_id=my_client_id&client_secret=my_client_secret", ParameterType.RequestBody);
IRestResponse response = client1.Execute(request1);
的事情是,當我從招搖UI(http://13.88.176.216/CherwellAPI/Swagger/ui/index#!/Service/Service_Token)執行相同的方法,我可以得到令牌沒有得到任何錯誤。在CURL請求
詳細說明:
捲曲
捲曲-X POST --header 「內容類型:應用程序/ x WWW的形式進行了urlencoded」 --header「接受:應用/ JSON」 -D 「grant_type =密碼& CLIENT_ID = my_client_id & client_secret = my_client_secret &用戶名= my_user_name &密碼= MY_PASSWORD」 「http://13.88.176.216/CherwellAPI/token?auth_mode=Internal」
請求URL http://13.88.176.216/CherwellAPI/token?auth_mode=Internal
這是從招搖的UI測試響應主體,而不是我的代碼:
{
"access_token": "the_acces_token",
"token_type": "bearer",
"expires_in": 1199,
"refresh_token": "the_refresh_token",
"as:client_id": "client_key",
"username": "user",
".issued": "date",
".expires": "other_date"
}
任何幫助將不勝感激。