响应不是来自使用改造的服务器

时间:2019-07-11 09:42:04

标签: android json gson retrofit2

您好,下面是根据响应向服务器发送请求。我没有得到响应。

我有一个名为Add的文本视图。如果按添加按钮,则要发送请求参数和响应作为状态。

基于响应,我正在显示Toast消息。 现在我的问题是没有从服务器得到任何响应。

Add.setOnClickListener (new View.OnClickListener ( ) {
            @Override
            public void onClick(View v) {


                name=et_building.getText ().toString ();
                String level="1";
//                final ProgressDialog progressDialog = new ProgressDialog(getActivity ());
//                progressDialog.setIndeterminate(true);
//                progressDialog.setMessage("Authenticating...");
//                progressDialog.setCanceledOnTouchOutside(false);
//                progressDialog.setCancelable(false);
//                progressDialog.show();



                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl(API.URL_BASE)
                        .addConverterFactory(ScalarsConverterFactory.create())
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();
                API service = retrofit.create(API.class);

                try{
                    JSONObject parmobject=new JSONObject ();
                    parmobject.put("name",name);
                    parmobject.put("level",level);
                    Call <NewBuilding> userCall = service.getbuildinglist (parmobject.toString());
                    userCall.enqueue(new Callback <NewBuilding> () {
                        @Override
                        public void onResponse(Call<NewBuilding> call, Response <NewBuilding> response) {

//                            if (progressDialog != null)
//                                progressDialog.dismiss();
                            Integer response1= response.code();
                            Log.d ("response", String.valueOf (response1));
                            if (response !=null && response.isSuccessful()&&response.code()==200) {

                                String status=response.body ().getStatus ();

                                if(status.equalsIgnoreCase ("success")){
                                    makeText(getActivity (), "Building successfully Added", Toast.LENGTH_SHORT).show();
                                    arrayList.add (name);
                                    adapter.notifyDataSetChanged ();

                                }


                            } else {
                                makeText(getActivity (), "Invalid EmailId and password", Toast.LENGTH_SHORT).show();

                            }
                        }

                        @Override
                        public void onFailure(Call<NewBuilding> call, Throwable t) {

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


            }
        });

Api_Service:

 @Headers("Content-Type: application/json")
    @POST("level/newbuilding")
    Call<NewBuilding> getbuildinglist(@Body String body);

0 个答案:

没有答案