Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- String query = "";
- HttpURLConnection connection = null;
- try {
- connection = (HttpURLConnection) new URL(query).openConnection();
- connection.setRequestMethod("GET");
- connection.setUseCaches(false);
- connection.setConnectTimeout(250);
- connection.setConnectTimeout(250);
- connection.connect();
- StringBuilder sb = new StringBuilder();
- if(HttpURLConnection.HTTP_OK == connection.getResponseCode()){
- BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line;
- while ((line = in.readLine()) !=null) {
- sb.append(line);
- sb.append("n");
- }
- System.out.println(sb.toString());
- }else{
- System.out.println("fail :" + connection.getResponseCode());
- }
- }catch (Throwable cause){
- cause.printStackTrace();
- }finally {
- if (connection != null){
- connection.disconnect();
- }
- }
- }
Add Comment
Please, Sign In to add comment