Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class Main {
    public static String makeGETRequest(String url) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet get = new HttpGet(url);

        // Fazendo a requisicao ao servidor
        try {
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            return httpclient.execute(get, responseHandler);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            return null;
        } catch (IllegalStateException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}