javaeye api httpclient实现一

package com.javaeye.api;
import java.io.IOException;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
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.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import it.sauronsoftware.base64.Base64;
public class Test {
	public static void main(String[] args) throws ClientProtocolException, IOException {
		String code = new  String(Base64.encode("username:password")); 
		HttpClient httpclient = new DefaultHttpClient();
		HttpGet httpget = new HttpGet("http://api.iteye.com/api/auth/verify");
		Header header = new BasicHeader("Authorization", code);
		httpget.addHeader(header);
		HttpResponse response = httpclient.execute(httpget);
		String string = EntityUtils.toString(response.getEntity(), "utf-8");
		System.out.println(string);
	}
}

 

你可能感兴趣的:(apache)