我正在使用 LoopJ AndroidAsyncHttp 从/向我的服务器获取/发布数据。我知道当我调用 .get 方法时,JSON 响应存储在 s 字符串中,如下所示:
client = new AsyncHttpClient();
client.get("https://example.com/generateToken.php", new TextHttpResponseHandler() {
@Override
public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
}
@Override
public void onSuccess(int i, Header[] headers, String s) {}
但是,如果我要发布到服务器,我如何获得服务器的响应?我在这里使用模板发布: http: //loopj.com/android-async-http/doc/com/loopj/android/http/RequestParams.html
具体来说,我的代码如下所示:
params = new RequestParams();
params.put("first_name", firstName);
params.put("last_name", lastName);
client = new AsyncHttpClient();
client.post("xxx.com/createCustomer.php", params, responseHandler);
我的服务器接受这些输入并返回一个令牌。如何检索此令牌?我是否必须在上面的 .post 代码之后立即调用 .get 方法?还是以某种方式自动回显?谢谢