【问题标题】:Request JSON Web-Server请求 JSON 网络服务器
【发布时间】:2018-04-16 14:43:40
【问题描述】:

我正在做一个 android 应用程序,我正在尝试为 Web 服务器实现 JSON 请求。我正在使用库:android-async-http-1.4.6.jar。 我写了以下代码:

public void RequestToServer() {

    try {

        AsyncHttpClient client = new AsyncHttpClient();
        RequestParams params = new RequestParams();
        // params.put("uid", User_id.toString());
        JSONObject cred = new JSONObject();

        cred.put("user",LoginActivity.m_user);
        cred.put("pwd", LoginActivity.m_pwd);
        Calendar c = Calendar.getInstance();
        cred.put("anno", Integer.toString(c.get(Calendar.YEAR)));

        StringEntity entity = new StringEntity(cred.toString());

        client.post(this, "http://vdctest.agrishare.com/list_up", entity, "application/json",responseHandler);

    }catch(Exception e)
    {

    }
}

但是我对 client.post 中的语音 responseeHandler 弄错了,我无法弄清楚问题是什么?谁能帮我? 提前感谢您的帮助。

【问题讨论】:

  • 发生了什么或没有发生什么?此外,空的 catch 块也不是一个好主意,因为您只是在默默地捕获可能会告诉您问题的错误
  • “误以为语音 responseeHandler”.. 这是什么意思?您的响应处理程序是否被调用?您是否认识到您正在调用的 url 正在返回 404?
  • 我无法填写代码,因为我弄错了responseHandler。我不明白是否缺少某些课程。
  • 抱歉,再次不确定:您无法编译和运行您的代码,对吗?

标签: android json web-services


【解决方案1】:

从 cmets 和典型的 google 示例中,我假设您出于某种原因错过了实现 responsehandler 方法。

我建议继续添加一个用于响应处理的内联函数,如此处接受的答案:

android-async-http post request with body

【讨论】:

    猜你喜欢
    • 2016-11-01
    • 2011-08-13
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-02
    相关资源
    最近更新 更多