[英]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.