我正在使用 Apache HttpComponents,由于某种原因,当我尝试使用查询参数执行 HttpPost 时,uri 不包含参数。
这是一段代码摘录:
List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>();
parametersBody.add(new BasicNameValuePair("response_type", "code"));
// continue adding parameters...
HttpPost post = new HttpPost("https://www.fitbit.com/oauth2/authorize");
post.setEntity(new UrlEncodedFormEntity(parametersBody, StandardCharsets.UTF_8));
HttpClient client = HttpClientBuilder.create().build();
HttpResponse response = client.execute(post);
当我使用 EntityUtils.toString(post.getEntity()) 检查帖子的参数时,所有参数都按预期存在......但是当我执行帖子时,它正在导航到“ https://www.fitbit.com/oauth2 /授权?空“
我需要在这里做什么?如果它有所作为,这不适用于 Android 应用程序。谢谢你的帮助。
编辑:目前,我正在做这样的解决方法:
String uri = "https://www.fitbit.com/oauth2/authorize?"
+ EntityUtils.toString(new UrlEncodedFormEntity(parametersBody, StandardCharsets.UTF_8);
HttpPost post = new HttpPost(uri);
client.execute(post);