HttpURLConnection conn = null;
try {
// 本机地址用localhost, 但是如果用模拟器加载本机的地址时,可以用ip(10.0.2.2)来替换
URL url = new URL("http://xxxxxxx/x/update.json");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");// 设置请求方法
conn.setConnectTimeout(5000);// 设置连接超时
conn.setReadTimeout(5000);// 设置响应超时, 连接上了,但服务器迟迟不给响应
conn.connect();// 连接服
简单的android http连接
最新推荐文章于 2021-05-26 12:11:31 发布