package com.baidu.net;
import java.io.IOException;
import org.apache.http.HttpEntity;
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.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
public class Network {
public static String getjson(String URL) {
String ss = "";
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(params, 5000);
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpGet get = new HttpGet(URL);
HttpClient client = new DefaultHttpClient(params);
try {
HttpResponse res = client.execute(get);
if (res.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = res.getEntity();
ss = EntityUtils.toString(entity, "utf-8");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ss;
}
}