【发布时间】:2015-10-07 10:55:57
【问题描述】:
我正在尝试在发布请求中使用参数调用服务,我的参数是 grant_type="password"、username="XXXXXX"、password="yyyyyyy" 并且我得到了像 {"error":"unsupported_grant_type"} 这样的异常
我在这里发送如下请求
String uri = Uri.parse(ServiceUrl.LOGIN_SERVER_URL)
.buildUpon()
.appendQueryParameter("grant_type","password")
.appendQueryParameter("username",userName.getText().toString().trim())
.appendQueryParameter("password", urlEncoded)
.build().toString();
我的调用服务代码以获取服务响应:
@SuppressWarnings("deprecation")
public static String httpPostQueryParamService(String Url) {
String serveresponse = null;
try {
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
ServiceUrl.timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
HttpConnectionParams.setSoTimeout(httpParams,
ServiceUrl.timeoutSocket);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost request = new HttpPost(Url);
request.addHeader("Content-Type","application/x-www-form-urlencoded");
HttpResponse response = client.execute(request);
HttpEntity responseEntity = response.getEntity();
serveresponse = EntityUtils.toString(responseEntity);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_GATEWAY) {
serveresponse = null;
}
} catch (Exception e) {
e.printStackTrace();
}
return serveresponse;
}
【问题讨论】:
-
那东西不应该像
grant_type=password&username=username&password=password一样进入身体吗? -
检查我的答案,我不能确定,但是当我这样做时,我必须将其添加为正文。
标签: android web-services