android中不支持grant类型的错误类型不支持_grant_type?

时间:2015-10-07 10:55:57

标签: android web-services

我正在尝试使用post请求中的参数调用服务,我的参数是grant_type =“password”,username =“XXXXXX”,password =“yyyyyyy”,我得到例外{{error“:”unsupported_grant_type“}

在这里,我发送的请求如下

<p>
         highlight me! this won't work because there's whitespace in the &lt;p&gt;
</p>

<p>highlight me! This should work because there isn't</p>

我的服务代码将服务响应作为:

String uri = Uri.parse(ServiceUrl.LOGIN_SERVER_URL)
                        .buildUpon()
                        .appendQueryParameter("grant_type","password")
                        .appendQueryParameter("username",userName.getText().toString().trim())
                        .appendQueryParameter("password", urlEncoded)
                        .build().toString();

1 个答案:

答案 0 :(得分:0)

我相信您需要将这些内容添加到方法体中,如下所示:

urlConnection.setDoOutput(true); 

// Add the body
DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream());
wr.writeBytes("&grant_type=password&username=username&password=password");
wr.flush(); 
wr.close();
相关问题