volley是轻量级的网络连接,适合频繁的网络连接,还是谷歌开发的,我就想不通了为啥不加入android的api库里面,还要找半天加依赖,终于找到了,网上的volley库版本都是2015年的,过时了,找了好几个库发现这个库最好用,
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); } }