【问题标题】:I want to print out the request using toast我想用 toast 打印出请求
【发布时间】:2017-11-13 12:18:30
【问题描述】:

我想在android中打印出请求,但是当我使用toast方法时,它无法解析该方法。

这是我的代码,

AsyncHttpClient client = new AsyncHttpClient();
client.get("http://localhost/moodle/webservice/rest/server.php?wstoken=0ac06623c66a3dd0e0e431f872a74710&wsfunction=core_user_create_users",params ,new AsyncHttpResponseHandler();
Toast.makeText(getApplicationContext(), client, Toast.LENGTH_LONG).show();

我想打印出请求。

【问题讨论】:

  • 您到底想在吐司中显示什么??
  • 我想打印出正在发送的请求。
  • 您无法在您的 toast 中显示该客户端。您要显示该网址吗?
  • 你能指导我怎么做吗

标签: java android


【解决方案1】:

您需要先阅读文档/AsyncHttpClient 的实现。你不会得到那样的回应。您需要为 AsyncHttpResponseHandler() 覆盖 onSuccess/onFailure 方法

client.get("http://localhost/moodle/webservice/rest/server.php?wstoken=0ac06623c66a3dd0e0e431f872a74710&wsfunction=core_user_create_users",params ,new AsyncHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
        Toast.makeText(getApplicationContext(),  new String(responseBody), Toast.LENGTH_LONG).show();
       }
};

【讨论】:

    【解决方案2】:

    尝试以下方法:

    Toast.makeText(getApplicationContext(), "http://localhost/moodle/webservice/rest/server.php?wstoken=0ac06623c66a3dd0e0e431f872a74710&wsfunction=core_user_create_users", Toast.LENGTH_LONG).show();
    

    假设你想显示url,你可以直接传递参数即url

    【讨论】:

      【解决方案3】:
      Toast.makeText(getApplicationContext(), client+"", Toast.LENGTH_LONG).show();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-26
        相关资源
        最近更新 更多