国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
httpclient 學(xué)習(xí)測(cè)試 實(shí)例 示例
package hasau;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.params.ConnRouteParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

/**
 *
 * @author    hasau 
 * 2010-11-5  上午09:51:25
 */
public class httpclientStudy {
  public static void main(String[] args) throws Exception {
//   javaHttpClient1();
   httpClientCookies();
  
  }
  
  
  private static void httpClientCookies() throws Exception{
   HttpClient httpClient = new DefaultHttpClient();
   HttpContext httpContext = new BasicHttpContext();
   HttpGet get = new HttpGet("http://localhost:8080/sgcms/back/logout.do");
   HttpResponse httpResponse = httpClient.execute(get, httpContext);
   HttpEntity entity = httpResponse.getEntity();
   String charSet = null;
   if(entity!=null){
    charSet = EntityUtils.getContentCharSet(entity);
    System.out.println(charSet);
    InputStream is = entity.getContent();
    BufferedReader  br = new BufferedReader(new InputStreamReader(is,"utf-8"));
    String text = null;
    String line = br.readLine();
    StringBuffer sb = new StringBuffer();
    while(line != null){
     sb.append(line+"\n");
     line = br.readLine();
    }
    is.close();
   }
   
   HttpPost httpPost = new HttpPost("http://localhost:8080/sgcms/back/ajaxJsonLogin.do'");
   List<NameValuePair> list = new ArrayList<NameValuePair>();
   list.add(new BasicNameValuePair("admin.loginName","hasau"));
   list.add(new BasicNameValuePair("admin.passwordMd5","hasau"));
   list.add(new BasicNameValuePair("admin.authCode",""));
   httpPost.setEntity(new UrlEncodedFormEntity(list,charSet));
   httpResponse = httpClient.execute(httpPost);
   entity = httpResponse.getEntity();
   if(entity != null){
    InputStream is = entity.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(is,"utf-8"));
    String line = br.readLine();
    String text = null;
    StringBuffer sb = new StringBuffer();
    while(line != null){
     sb.append(line+"\n");
     line=br.readLine();
    }
    System.out.println(sb.toString());
   }
   
   httpClient.getConnectionManager().shutdown();
  }
  private static void javaHttpClient1() throws ClientProtocolException, IOException{
   HttpClient httpClient = new DefaultHttpClient();
   httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, new HttpHost("121.12.249.207",3128));
   HttpGet get =new HttpGet("   HttpContext context = new BasicHttpContext();
   HttpResponse response = httpClient.execute(get,context);
   HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);//http://localhost:8080
   HttpUriRequest request = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);// cms/back/hasau.jsp
   
   
   HttpEntity entity = response.getEntity();
   String charset = EntityUtils.getContentCharSet(entity);
   System.out.println(charset);
   if(entity!=null){
    InputStream is = entity.getContent();
    BufferedReader buf = new BufferedReader(new InputStreamReader(is,"gbk"));
    String content="";
    String line = buf.readLine();
    while(line!=null){
     content += line+"\n";
     line=buf.readLine();
     
    }
    System.out.println(content);
    is.close();
   }
   httpClient.getConnectionManager().shutdown();
   
  }
  
  private static void javaNetJsoup() throws IOException  {
   String key = "
   URL url = new URL(key);
   Proxy proxy = new Proxy(Proxy.Type.HTTP,new InetSocketAddress("192.168.12.32",80));
   
   HttpURLConnection con = (HttpURLConnection)url.openConnection(proxy);
   con.setFollowRedirects(false);
   con.setRequestMethod("GET");
   BufferedReader buf = new BufferedReader(new InputStreamReader(con.getInputStream(),"gbk"));
   
   InputStream in = url.openStream();
   buf = new BufferedReader(new InputStreamReader(in,"gbk"));
   String line = buf.readLine();
   String content = "";
   while(line!=null){
    content +=line;
    line=buf.readLine();
   }
   in.close();
   System.out.println(content); 
  
   Document document = Jsoup.parse(url, 1000*10);
   System.out.println(document.html());
  }
}
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Android中使用HTTP服務(wù)
使用HTTP Client構(gòu)建Web客戶(hù)端
Android之向中國(guó)天氣網(wǎng)發(fā)送GET請(qǐng)求獲取JSON數(shù)據(jù)實(shí)例
httpclient
網(wǎng)絡(luò)爬蟲(chóng)(網(wǎng)絡(luò)蜘蛛)之網(wǎng)頁(yè)抓取舉例說(shuō)明
impala java api 操作
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服