参考博文:
关于HttpClient的总结(一) java中Logger.getLogger
/** * Bad Request: The request was invalid. An accompanying error message will * explain why. This is the status code will be returned during rate * limiting. * (Rate Limiting):对数据包进行修整。防止不正常数据包攻击目标, * 对每个数据流业务进行修整,处罚长时间消耗大量资源的源头。 */ public static final int BAD_REQUEST = 400;
/** * Service Unavailable: The Weibo servers are up, but overloaded with * requests. Try again later. The search and trend methods use this to * indicate when you are being rate limited. */ public static final int SERVICE_UNAVAILABLE = 503;
包含的参数
/**The class represents an authentication scope consisting of a host name, a port number, a realm name and an authentication scheme name which Credentials apply to.*/ private AuthScope mAuthScope
private DefaultHttpClient mClient;
private BasicHttpContext localcontext;
private String mUserId;
private String mPassword;
private OAuthClient mOAuthClient;
private String mOAuthBaseUrl = Configuration.getOAuthBaseUrl();
简述Configuration.class
public class Configuration { private static Properties defaultProperty; static { init(); } /* package */static void init() { defaultProperty.setProperty("fanfoudroid.oauth.baseUrl","http://fanfou.com/oauth"); .... 通过public static String getOAuthBaseUrl() { return getProperty("fanfoudroid.oauth.baseUrl"); } public static String getProperty(String name) { return getProperty(name, null); } //fallbackValue当没有这个property时被返回值 public static String getProperty(String name, String fallbackValue) { String value; try { value = System.getProperty(name, fallbackValue); if (null == value) { //从自定义默认的Property取值 value = defaultProperty.getProperty(name); //从系统取值 ..... value = System.getProperty(fallback); ..... } catch (AccessControlException ace) { // Unsigned applet cannot access System properties value = fallbackValue; } //去掉value里面包含{ }..用到substring,indexof..不做介绍 return replace(value); }
HttpClient.class 的无参构造类
//设置日志输出 // Create and initialize HTTP parameters // Create and initialize scheme registry // Create an HttpClient with the ThreadSafeClientConnManager. // Support GZIP public HttpClient() { prepareHttpClient(); /** * Sets the consumer key and consumer secret.<br> */ setOAuthConsumer(null, null, null); }
//设置日志输出 private void enableDebug() { Log.d(TAG, "enable apache.http debug"); java.util.logging.Logger.getLogger("org.apache.http").setLevel( java.util.logging.Level.FINEST); java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel( java.util.logging.Level.FINER); java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel( java.util.logging.Level.OFF);