Android HttpClient设置User_agent的方式

 
  
 
  
HttpClient mHttpClient = new DefaultHttpClient();
HttpParams params = mHttpClient.getParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, FixedValue.NET_TIMEOUT);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, FixedValue.NET_TIMEOUT);
StringBuilder user_agent = new StringBuilder();
user_agent.append("device:2");
user_agent.append(";system:"+android.os.Build.VERSION.RELEASE);
user_agent.append(";version:"+SystemUtils.getAppVersionName());
user_agent.append(";device_id:"+SystemUtils.getDeviceId());
params.setParameter("http.useragent", user_agent.toString());
HttpResponse httpResponse = mHttpClient.execute(httpPost);


在Apache文档里可以看到
 
  
 
  
 
  
 
  
 
 

你可能感兴趣的:(Android)