我在ASP.NET应用程序中将Visual Studio 2010和RestSharp用于我的API调用,但是每次遇到BadRequest时,它都像C#控制台应用程序和Postman中的魅力一样工作。
var client = new RestClient("https://accountsuat.cardconnect.com/auth/realms/cardpointe/protocol/openid-connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("undefined", "username=" + username + "&password=" + password + "&grant_type=password" + "&client_id=copilot" + "&client_secret=" + client_secret, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);