日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HttpClient模拟http请求

發布時間:2025/7/14 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HttpClient模拟http请求 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近工作中使用到了兩個jar包?httpclient.jar, httpcore.jar

?

?HttpClient 的 abort(終止)程序示例

[java] view plaincopyprint? /* * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.http.examples.client; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; /** * This example demonstrates how to abort an HTTP method before its normal completion. * 在HttpClient 普通完成前調用abort方法對其進行終止 */ public class ClientAbortMethod { public final static void main(String[] args) throws Exception { HttpClient httpclient = new DefaultHttpClient(); try { HttpGet httpget = new HttpGet("http://www.apache.org/"); System.out.println("executing request " + httpget.getURI()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } System.out.println("----------------------------------------"); // Do not feel like reading the response body // Call abort on the request object // 不打算讀取response body // 調用request的abort方法 httpget.abort(); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources // 當HttpClient實例不再需要是,確保關閉connection manager,以釋放其系統資源 httpclient.getConnectionManager().shutdown(); } } }

 

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader;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;public class TTT {/*** @param args* @throws IOException* @throws ClientProtocolException*/public static void main(String[] args) throws ClientProtocolException, IOException{// 創建HttpClient實例HttpClient httpclient = new DefaultHttpClient();// 創建Get方法實例HttpGet httpgets = new HttpGet("http://www.baidu.com");HttpResponse response = httpclient.execute(httpgets);HttpEntity entity = response.getEntity();if (entity != null){InputStream instreams = entity.getContent();String str = convertStreamToString(instreams);System.out.println(str);//終止http請求和響應httpgets.abort();}}public static String convertStreamToString(InputStream is){BufferedReader reader = new BufferedReader(new InputStreamReader(is));StringBuilder sb = new StringBuilder();String line = null;try{while ((line = reader.readLine()) != null){sb.append(line + "\n");}} catch (IOException e){e.printStackTrace();} finally{try{is.close();} catch (IOException e){e.printStackTrace();}}return sb.toString();}}

  

轉載于:https://www.cnblogs.com/wuxinliulei/p/4859721.html

總結

以上是生活随笔為你收集整理的HttpClient模拟http请求的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 99re伊人| 激情五月开心婷婷 | 亚洲第一狼人区 | 俺去久久 | 欧美爱爱小视频 | 秋霞国产一区 | 香蕉国产| 三级伦理视频 | 欧美理伦片在线播放 | 久久精品国产成人av | 国产女人爽到高潮a毛片 | 好吊操av | 99在线精品免费视频 | 中文字幕乱码人妻一区二区三区 | 日韩色资源 | 午夜黄网 | 无码精品人妻一区二区三区漫画 | 精品国产乱码久久久久久久 | 日韩和的一区二区 | 韩国黄色视屏 | 三男一女吃奶添下面 | 国产精品久久九九 | 国产一区精品在线 | 成人在线免费视频播放 | 午夜色综合 | 黄色一级片在线免费观看 | 一本色道久久综合狠狠躁的推荐 | 日本精品黄 | 国产中文字幕在线播放 | 黄色性视频网站 | 视频在线观看免费大片 | 日韩黄片一区二区 | 91美女视频在线观看 | 51精品国产 | 日韩欧美不卡在线 | 亚洲一区成人 | 国产人妻一区二区三区四区五区六 | 美女av毛片 | 成人激情五月天 | 日韩欧美一区二区三区在线 | 天天鲁 | 欧美三级欧美一级 | 日韩成人精品一区二区三区 | 天天干天天综合 | 少妇一夜三次一区二区 | 国产黄色视 | 师生出轨h灌满了1v1 | 在线观看视频你懂得 | 欧美日韩不卡一区二区 | 精品久久久久久久免费人妻 | 正在播放木下凛凛xv99 | 射在线 | 久久精品免费网站 | 香蕉av在线 | 日韩亚洲欧美精品 | 亚洲一区二区三区精品视频 | 亚洲成a人片777777久久 | av一二三四区 | 亚洲av无码片一区二区三区 | 夜色精品 | 中国无码人妻丰满熟妇啪啪软件 | 一本色道综合久久欧美日韩精品 | 国产无遮掩| 日韩在线观看 | 91高清国产 | 国产精品12p | 免费毛片一区二区三区 | 久久婷婷一区二区 | 欧美成人影音 | 日韩精品aaa| 欧美在线视频a | 69人妻精品久久无人专区 | 亚洲靠逼| 国内自拍第二页 | 久久久久久久久久久久久久久久久久久久 | 亚洲一区二区三区三州 | 金瓶风月在线 | 免费毛片网站 | av在线入口 | 情欲少妇人妻100篇 黄色一级片欧美 | 一区二区三区激情视频 | 中文字幕黄色 | 国语av在线 | 日韩三级a | 日韩精品视频播放 | 国产美女永久免费 | 国产欧美久久久 | 久久白浆 | 中日韩av在线 | 免费a级片在线观看 | 人人干人人艹 | 成人免费高清在线观看 | 四虎影视免费看 | 欧美日韩人妻精品一区二区 | 色666| 潘金莲一级淫片aaaaa武则天 | 久操视频在线免费观看 | 国产成人无码精品久在线观看 | 国产山村乱淫老妇女视频 |