1

我想使用 AndroidAsync 库发出 post http 请求,但我无法将内容类型更改为'application/x-www-form-urlencoded'for request

AsyncHttpPost post = new AsyncHttpPost(LOGIN_URL);
MultipartFormDataBody body = new MultipartFormDataBody();
body.addStringPart("grant-type", "password");
body.addStringPart("username", userName);
body.addStringPart("password", password);
body.setContentType("application/x-www-form-urlencoded")
post.setBody(body);

AsyncHttpClient.getDefaultInstance().executeJSONObject(url, new     AsyncHttpClient.JSONObjectCallback() {
// Callback is invoked with any exceptions/errors, and the result, if available.
@Override
public void onCompleted(Exception e, AsyncHttpResponse response, JSONObject result) {
    if (e != null) {
        e.printStackTrace();
        return;
    }
    System.out.println("I got a JSONObject: " + result);
}
});

我不知道该怎么办。

4

0 回答 0