准确HttpUrlConnection
来源:互联网 发布:js 点击展开和隐藏 编辑:程序博客网 时间:2024/04/28 09:26
package com.bwie.banner_pulltorfl;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by ${王新杰} on 2017/10/23.
*/
public class HttpUrlConnection {
public static String getJson(String urldata) {
try {
URL url = new URL(urldata);
HttpURLConnection httpurlConnection = (HttpURLConnection) url.openConnection();
httpurlConnection.setRequestMethod("GET");
httpurlConnection.setReadTimeout(8000);
int responseCode = httpurlConnection.getResponseCode();
if (responseCode == 200) {
InputStream inputStream = httpurlConnection.getInputStream();
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String json = "";
while ((json = bufferedReader.readLine()) != null) {
stringBuilder.append(json);
}
return stringBuilder.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by ${王新杰} on 2017/10/23.
*/
public class HttpUrlConnection {
public static String getJson(String urldata) {
try {
URL url = new URL(urldata);
HttpURLConnection httpurlConnection = (HttpURLConnection) url.openConnection();
httpurlConnection.setRequestMethod("GET");
httpurlConnection.setReadTimeout(8000);
int responseCode = httpurlConnection.getResponseCode();
if (responseCode == 200) {
InputStream inputStream = httpurlConnection.getInputStream();
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String json = "";
while ((json = bufferedReader.readLine()) != null) {
stringBuilder.append(json);
}
return stringBuilder.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
阅读全文
0 0
- 准确HttpUrlConnection
- 准确HttpUrlConnection
- 为什么使用HttpUrlConnection时候,用available方法不准确
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- httpurlconnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLconnection
- HttpURLConnection
- tomcat发布zookeeper项目的时候找不到很多文件
- Android Studio解决fetching documentation问题——悬浮不能显示文档
- 前端精选文摘:那些年我们一起清除过的浮动
- 大话设计模式----装饰模式
- mysql 时间戳格式化函数from_unixtime
- 准确HttpUrlConnection
- ThinkPHP 切换数据库
- Python集合(set)
- 用xib建立一个自定义view,在view上添加并排按钮
- C#Socket Clinet
- Spring MVC框架搭建扩展--多数据源配置(二)
- 修改Ubuntu的aptget源为阿里源的方法
- react_basic(5)
- 查看Android源码的时候一些方法或者类找不到的原因