Return to Snippet

Revision: 33181
at October 6, 2010 22:43 by cha0s


Updated Code
package yourpackage;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;

public class HttpClientGetTest {
	public static void main(String[] args) throws IllegalArgumentException, IOException {
		get();
	}
	
	private static void get() throws ClientProtocolException, IOException {
	    HttpClient httpclient = new DefaultHttpClient();
	    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

	    HttpGet get = new HttpGet("your-url");	    
	    HttpResponse response = httpclient.execute(get);
	    HttpEntity   resEntity = response.getEntity();
	    int returnCode = response.getStatusLine().getStatusCode();
	}
}

Revision: 33180
at October 6, 2010 20:56 by cha0s


Updated Code
package yourpackage;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;

public class HttpClientGetTest {
	/**
	 * @param args
	 * @throws IOException 
	 * @throws IllegalArgumentException 
	 */
	public static void main(String[] args) throws IllegalArgumentException, IOException {
		get();
	}
	
	private static void get() throws ClientProtocolException, IOException {
	    HttpClient httpclient = new DefaultHttpClient();
	    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

	    HttpGet get = new HttpGet("your-url");	    
	    HttpResponse response = httpclient.execute(get);
	    HttpEntity   resEntity = response.getEntity();
	    int returnCode = response.getStatusLine().getStatusCode();
	}
}

Revision: 33179
at October 6, 2010 20:55 by cha0s


Initial Code
package yourpackage;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;

public class HttpClientGetTest {
	/**
	 * @param args
	 * @throws IOException 
	 * @throws IllegalArgumentException 
	 */
	public static void main(String[] args) throws IllegalArgumentException, IOException {
		get();
	}
	
	private static void get() throws ClientProtocolException, IOException {
	    HttpClient httpclient = new DefaultHttpClient();
	    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

	    HttpGet get = new HttpGet("your-url");	    
	    HttpResponse response = httpclient.execute(get);
	    HttpEntity   resEntity = response.getEntity();
	    int returnCode = response.getStatusLine();
	}
}

Initial URL

                                

Initial Description
Required libraries: http://hc.apache.org/downloads.cgi

Initial Title
Http-Client GET

Initial Tags
http, java

Initial Language
Java