【问题标题】:Unsupported grant type with APIAPI 不支持的授权类型
【发布时间】:2016-04-25 21:33:46
【问题描述】:

我正在尝试从服务器响应中获取令牌,它适用于 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);

【问题讨论】:

    标签: java android json api token


    【解决方案1】:

    终于找到了解决办法:

    替换:

      post.setEntity(new StringEntity(obj.toString(), "UTF-8"));
    

    与:

                    post.setEntity(new StringEntity("grant_type=password&username=0000@gmail.com&password=00000", "UTF-8"));
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2018-07-01
      • 1970-01-01
      • 2017-09-18
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      相关资源
      最近更新 更多