android http随笔


 private static GetMethod getHttpGet(String url, String cookie, String userAgent) {
  GetMethod httpGet = new GetMethod(url);
  // 设置 请求超时时间
  httpGet.getParams().setSoTimeout(TIMEOUT_SOCKET);
//  httpGet.setRequestHeader("Host", "192.168.1.236");
  httpGet.setRequestHeader("Connection","Keep-Alive");
  httpGet.setRequestHeader("Cookie", cookie);

//设置客户端发送给服务端的头信息(如android设备等信息)
  httpGet.setRequestHeader("User-Agent", userAgent);
  return httpGet;
 }
 
 private static PostMethod getHttpPost(String url, String cookie, String userAgent) {
  PostMethod httpPost = new PostMethod(url);
  // 设置 请求超时时间
  httpPost.getParams().setSoTimeout(TIMEOUT_SOCKET);
//  httpPost.setRequestHeader("Host", "192.168.1.236");
  httpPost.setRequestHeader("Connection","Keep-Alive");
  httpPost.setRequestHeader("Cookie", cookie);
  httpPost.setRequestHeader("User-Agent", userAgent);
  return httpPost;
 }

你可能感兴趣的:(android)