I am unable to make a network call using Volley

前端 未结 4 1541
甜味超标
甜味超标 2021-01-24 09:13

When I am making a network call using jsonObject request. I am not receiving any response. I always receive HTTP response for request=<[ ] before my URL. I have tried these l

4条回答
  •  滥情空心
    2021-01-24 09:41

    Try this using String Request

    public class TestActivity extends AppCompatActivity {
            RequestQueue requestQueue;
            String DATA_URL = "http://ec2-54-147-238-136.compute-1.amazonaws.com/hmc/api/getnewsfeeds?order=asc";
        
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                requestQueue = Volley.newRequestQueue(this);
                callApi();
            }
        
            private void callApi() {
                StringRequest stringRequest = new StringRequest(Request.Method.GET, DATA_URL, new Response.Listener() {
                    @Override
                    public void onResponse(String response) {
                        Log.e("res", response);
                    }
        
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("onErrorResponse: ", error.getLocalizedMessage());
                    }
        
                });
        
                requestQueue.add(stringRequest);
            }
    

提交回复
热议问题