2013-04-03 15:53:57 +02:00
|
|
|
package com.commafeed.backend;
|
|
|
|
|
|
|
|
|
|
import org.apache.http.HttpEntity;
|
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
2013-04-05 23:02:12 +02:00
|
|
|
import org.apache.http.client.params.CookiePolicy;
|
|
|
|
|
import org.apache.http.client.params.HttpClientParams;
|
2013-04-03 15:53:57 +02:00
|
|
|
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
|
|
import org.apache.http.params.HttpConnectionParams;
|
2013-04-05 23:02:12 +02:00
|
|
|
import org.apache.http.params.HttpParams;
|
2013-04-03 15:53:57 +02:00
|
|
|
import org.apache.http.params.HttpProtocolParams;
|
|
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
|
|
|
|
public class HttpGetter {
|
|
|
|
|
|
|
|
|
|
public String get(String url) throws Exception {
|
|
|
|
|
return new String(getBinary(url), "UTF-8");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] getBinary(String url) throws Exception {
|
|
|
|
|
byte[] content = null;
|
|
|
|
|
|
|
|
|
|
HttpClient httpclient = new DefaultHttpClient();
|
2013-04-05 23:02:12 +02:00
|
|
|
HttpParams params = httpclient.getParams();
|
|
|
|
|
HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES);
|
|
|
|
|
HttpProtocolParams.setContentCharset(params, "UTF-8");
|
2013-04-09 11:50:21 +02:00
|
|
|
HttpConnectionParams.setConnectionTimeout(params, 4000);
|
|
|
|
|
HttpConnectionParams.setSoTimeout(params, 4000);
|
2013-04-03 15:53:57 +02:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
HttpGet httpget = new HttpGet(url);
|
2013-04-08 14:45:32 +02:00
|
|
|
httpget.addHeader("Pragma", "No-cache");
|
|
|
|
|
httpget.addHeader("Cache-Control", "no-cache");
|
2013-04-03 15:53:57 +02:00
|
|
|
HttpResponse response = httpclient.execute(httpget);
|
|
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
content = EntityUtils.toByteArray(entity);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
httpclient.getConnectionManager().shutdown();
|
|
|
|
|
}
|
|
|
|
|
return content;
|
|
|
|
|
}
|
|
|
|
|
}
|