为什么我在访问Android中的URL而不是邮递员时遇到错误

时间:2017-01-23 13:58:34

标签: android android-asynctask

尝试从android工作室中的url访问json数据时获取非对象"," status_code":500的属性,我在Asynctask类中使用HttpUrlConnection并通过Postman检查它它正在正常工作获取数据,但从Android代码它显示错误

     class DashboardAdmin extends AsyncTask<String,Void,String>
    {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            Log.d("In Dashboard","in class Dashboard");
        }
        @Override
        protected String doInBackground(String... params) {
            URL url;
            String response="";
            HttpURLConnection connection ;
            BufferedReader bufferedReader;
            StringBuffer  buffer;
            String token=Appconfig.TOKEN;
            try {
                url = new URL(Appconfig.DASHBOARD_URL+token);
                connection = (HttpURLConnection) url.openConnection();
                int responseCode = connection.getResponseCode();
                if (responseCode == HttpsURLConnection.HTTP_OK) {
                    String line="";
                    bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                    buffer=new StringBuffer();
                    //Log.d("Output",br.toString());
                    while ((line = bufferedReader.readLine()) != null) {
                        // response += line;
                        buffer.append(line);
                        Log.d("output lines in dash", line);
                    }
                    response=buffer.toString();

                    //System.out.println("success=" + json.get("success"));
                    Log.i("response in dash", response);
                }
                else {
                    InputStreamReader inputStreamReader = new InputStreamReader(connection.getErrorStream());
                    bufferedReader = new BufferedReader(inputStreamReader);
                    buffer=new StringBuffer();

                    String line ="";
                    while ((line = bufferedReader.readLine()) != null) {
                        //  response += line;
                        buffer.append(line);
                        Log.d("output lines in dash", line);
                    }
                    response=buffer.toString();
                    Log.i("response in dash", response);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            // connection.disconnect();
            return response;
        }
        @Override
        protected void onPostExecute(String response) {
/*            try {
                 //Log.i("response--",response);
                JSONObject jsonObject=new JSONObject(response);
                dashboardArrayList1.add(jsonObject.getInt("customers"));
                dashboardArrayList1.add(jsonObject.getInt("contracts"));
                dashboardArrayList1.add(jsonObject.getInt("products"));
                dashboardArrayList1.add(jsonObject.getInt("opportunities"));

                JSONArray jsonArray=jsonObject.getJSONArray("opportunity_leads");
                for (int i=0;i<jsonArray.length();i++)
                {    OppLeads oppLeads=new OppLeads();
                    JSONObject object=jsonArray.getJSONObject(i);
                    oppLeads.setMonth(object.getString("month"));
                    oppLeads.setMonth(object.getString("year"));
                    oppLeads.setOpp(object.getInt("opportunity"));
                    oppLeads.setLeads(object.getInt("leads"));
                    dashboardArrayList2.add(oppLeads);
                }

                recyclerView.setAdapter(new DashboradAdapter(dashboardArrayList1));
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                RecyclerView.LayoutManager layoutManager=new GridLayoutManager(getActivity(),2);

                recyclerView.setLayoutManager(layoutManager);*/

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

        }
    }

错误: - 尝试获取非对象的属性&#34;,&#34; status_code&#34;:500 我在收到服务器响应时收到错误

0 个答案:

没有答案