简体   繁体   English

请求中缺少 Grant_type

[英]Grant_type missing in request

I'm trying to get token access (protocol oauth2) to dynamics 365.我正在尝试获得对动态 365 的令牌访问(协议 oauth2)。

That's the code that build and execute the http post request:这是构建和执行 http post 请求的代码:

URI uri = new URIBuilder()
                    .setScheme("https")
                    .setHost("login.microsoftonline.com")
                    .setPath("/"+PropertyUtils.getInstance().getProperty("AD_TENANT_ID")+"/oauth2/token")
                    .setParameter("grant_type", "client_credentials")
                    .setParameter("client_id", PropertyUtils.getInstance().getProperty("CLIENT_ID"))
                    .setParameter("resource", PropertyUtils.getInstance().getProperty("RESOURCE"))
                    .setParameter("client_secret", PropertyUtils.getInstance().getProperty("CLIENT_SECRET"))
                    .build();
            HttpPost post = new HttpPost(uri);
            HttpResponse response = client.execute(post);

the response json is:响应 json 是:

{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r ...

why response tell me that grant_type is missing when it's in the request as a parameter?为什么响应告诉我,当它作为参数出现在请求中时,grant_type 丢失了?

You are trying to perform the request putting those parameters in the URI as query parameters.您正在尝试执行将这些参数作为查询参数放在 URI 中的请求。 Although those parameters needs to be put in the body of the request as form url encoded.尽管这些参数需要作为表单 url 编码放入请求正文中。

{"Content-Type": "application/x-www-form-urlencoded"} {"Content-Type": "application/x-www-form-urlencoded"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keycloak 缺少表单参数:grant_type - Keycloak Missing form parameter: grant_type 登录 Spotify 时“grant_type 参数丢失” API - "grant_type parameter is missing" in login Spotify API google oauth api v2中缺少grant_type参数? - missing grant_type parameter in google oauth api v2? 正在访问Google oAuth,但授予的Grant_type无效(错误请求) - Accessing Google oAuth giving invalid grant_type (Bad request) 使用 DocuSign AuthenticationApi.login() 进行传统身份验证时出错 - 缺少 grant_type/code - Error using DocuSign AuthenticationApi.login() for Legacy Authentication - Missing grant_type/code 总是获取无效的grant_type参数或缺少参数,但适用于邮递员 - always getting Invalid grant_type parameter or parameter missing but works on postman Google Oauth2身份验证返回“缺少必需的参数:grant_type” - Google Oauth2 authentication returns “Required parameter is missing: grant_type” 带有笔划库的Box OAuth2 API上无效的grant_type参数或参数丢失 - Invalid grant_type parameter or parameter missing on Box OAuth2 API with scribe library Spring-Security-OAuth2中的grant_type - grant_type in Spring-Security-OAuth2 身份验证流程中grant_type = client_credentials和grant_type = password之间的区别? - Difference between grant_type=client_credentials and grant_type=password in Authentication Flow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM