API 不支持的授权类型
Unsupported grant type with API
我正在尝试从服务器响应中获取令牌,它与 postMan 配合使用效果很好,但是当使用 android 进行调试时出现错误:
unsupported_grant_type
这是我的代码:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(LoginURL);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
// post.setHeader("Accept", "application/x-www-form-urlencoded");
JSONObject obj = new JSONObject();
try {
obj.put("grant_type", "password");
obj.put("password", PasswordEditText);
obj.put("username", EmailEditText+"gfg");
post.setEntity(new StringEntity(obj.toString(), "UTF-8"));
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
results = EntityUtils.toString(entity);
myObject = new JSONObject(results);
终于找到解决办法了:
替换:
post.setEntity(new StringEntity(obj.toString(), "UTF-8"));
与:
post.setEntity(new StringEntity("grant_type=password&username=0000@gmail.com&password=00000", "UTF-8"));
我正在尝试从服务器响应中获取令牌,它与 postMan 配合使用效果很好,但是当使用 android 进行调试时出现错误:
unsupported_grant_type
这是我的代码:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(LoginURL);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
// post.setHeader("Accept", "application/x-www-form-urlencoded");
JSONObject obj = new JSONObject();
try {
obj.put("grant_type", "password");
obj.put("password", PasswordEditText);
obj.put("username", EmailEditText+"gfg");
post.setEntity(new StringEntity(obj.toString(), "UTF-8"));
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
results = EntityUtils.toString(entity);
myObject = new JSONObject(results);
终于找到解决办法了:
替换:
post.setEntity(new StringEntity(obj.toString(), "UTF-8"));
与:
post.setEntity(new StringEntity("grant_type=password&username=0000@gmail.com&password=00000", "UTF-8"));