排球成功和错误代码处理

时间:2016-08-19 07:10:38

标签: android-studio android-volley

我基本上是凌空新手,但与apache http旧库不同,我曾经这样处理响应以及状态代码,以显示关于成功和失败响应的aler对话:

 @Override
    protected String doInBackground(Void... params) {
        String mre = null;

            stringEntity=new StringEntity(jsonObject.toString());
            httpPost.setEntity(stringEntity);
            httpPost.setHeader("Content-type", "application/json");


            httpResponse=httpClient.execute(httpPost);
            int statusCode=httpResponse.getStatusLine().getStatusCode();


            switch (statusCode){
                case 200:
                    entity = httpResponse.getEntity();
                    System.out.println("Entity post is: "
                            + EntityUtils.toString(entity));
                    mre = "200";
                    Log.d("SUCCESS","YES FINALLY");
                    Log.d("Ok",entity.toString());

                    break;
                case 412:
                    mre = "412";
                    Log.d("412", "412 WE MEET AGAIN)");
                    break;
                default:
                    mre="unknown";
                    Log.i("Unknown","Unknown Server Error");

            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return mre;
    }

    @Override
    protected void onPostExecute(String mre) {
        super.onPostExecute(mre);
        hideDialog();

        if(mre.equalsIgnoreCase("200")){

         //HANDLE HERE
        }
        else if(mre.equalsIgnoreCase("412")){


            //HANDLE HERE

        }
        else
        if(mre.equalsIgnoreCase("unknown")){

            //HANDLE HERE


        }

但是在排球中我很困惑,我需要处理从服务器收到的每个状态代码,以便我可以向用户显示一条消息。(成功/失败)

有点帮助会深深感激

0 个答案:

没有答案