Android - HTTP GET Request

后端 未结 4 2124
迷失自我
迷失自我 2020-12-29 12:30

I have developed a HTTP GET Method that clearly works.

public class GetMethodEx {


public String getInternetData() throws Exception{

        new TrustAllMa         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 13:17

    Take care, with the new version of API all this code is deprecated !

    Here is an example of http get with the new api.

    RequestQueue queue = Volley.newRequestQueue(this);
    String url ="http://www.google.com";
    
    // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener() {
        @Override
        public void onResponse(String response) {
            // Display the first 500 characters of the response string.
            mTextView.setText("Response is: "+ response.substring(0,500));
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mTextView.setText("That didn't work!");
        }
    });
    // Add the request to the RequestQueue.
    queue.add(stringRequest);
    

    Source from android website : https://developer.android.com/training/volley/simple.html

提交回复
热议问题