volley是輕量級的網絡鏈接,適合頻繁的網絡鏈接,仍是谷歌開發的,我就想不通了爲啥不加入android的api庫裏面,還要找半天加依賴,終於找到了,網上的volley庫版本都是2015年的,過期了,找了好幾個庫發現這個庫最好用,android
implementation 'com.dubsmash.volley:library:2.0.1'
一樣是右鍵module打開module設置輸入volley回車找到這個依賴
public class MainActivity extends AppCompatActivity { private RequestQueue queues ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); queues = Volley.newRequestQueue(this); StringRequest stringRequest = new StringRequest("https://blog.csdn.net/u012602304/article/details/79170137", new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d("TAG", response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("TAG", error.getMessage(), error); } }); queues.add(stringRequest); } }