关于curl java 模拟http请求
来源:互联网 发布:java重载构造函数格式 编辑:程序博客网 时间:2024/05/15 23:48
近期笔者项目需求java模拟http请求,获取dns解析 tcp连接等详细耗时信息。
java api中提供的urlConnection 及apache提供的httpClient都不能胜任该需求,二次开发太费时间。于是google之。
最后 得出两种解决办法:
一是使用HTTP4J。
该开源项目使用socket方式,模拟请求,记录时间戳,基本满足需求。对于header自定义等细节,可在此基础上比较方便的二次开发。只是,其中有一些bug需要修复,如https链接时获取不到ssl时间等。使用该项目的风险在于不稳定和不可控性。
稍作改动后的http4j代码。
http://download.csdn.net/detail/zhongyuan_1990/8837281
二是使用curl。
google之,curl本身没有对java的支持,由第三份提供了binding用来使用curl。可能是笔者能力有限,未能成功在windows编译它。google也没有找到相关javacurl.dll的资源下载。最后不得不放弃。选择使用命令行的模式操作curl。
java 使用curl命令 demo
package com.netbirdtech.libcurl.test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class test {public static void main(String[] args) {String []cmds = {"curl", "-i", "-w", "状态%{http_code};DNS时间%{time_namelookup};"+ "等待时间%{time_pretransfer}TCP 连接%{time_connect};发出请求%{time_starttransfer};"+ "总时间%{time_total}","http://www.baidu.com"};ProcessBuilder pb=new ProcessBuilder(cmds);pb.redirectErrorStream(true);Process p;try {p = pb.start();BufferedReader br=null;String line=null;br=new BufferedReader(new InputStreamReader(p.getInputStream()));while((line=br.readLine())!=null){System.out.println("\t"+line);}br.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
0 0
- 关于curl java 模拟http请求
- curl模拟http请求
- curl 模拟http发送请求
- 用curl模拟http请求获取网页
- PHP curl 模拟http https请求
- php中实现curl模拟Http请求
- 【curl和wget命令】模拟HTTP请求
- java模拟http请求
- java模拟HTTP请求
- Linux 下curl模拟Http 的get or post请求
- Linux 下curl模拟Http 的get or post请求。
- Linux 下curl模拟Http 的get or post请求。
- Linux 下curl模拟Http 的get or post请求
- Linux 下curl模拟Http 的get or post请求
- Linux 下curl模拟Http 的get or post请求
- Linux 下curl模拟Http 的get or post请求
- curl模拟Http 的get 或 post请求
- 一个简单实用的cURL模拟http请求的函数
- iOS在线播放--影音播放的两个方式
- 黑马程序员--------面向对象继承和多态
- Linux下双物理网卡设置成虚拟网卡
- Java Reflection(一):Java反射指南
- HTML5之localStorage-sessionStorage
- 关于curl java 模拟http请求
- 安卓xutils的使用
- mysql支持存储emoji表情
- linux grep 正则表达式
- 串口线传输距离之讨论
- 该 App 的 Info.plist 不能包含阻碍在任何 iOS 设备上打开此 App 的 UIRequiredDeviceCapabilities 键值
- Hibernate
- Android数据的存储方式简介
- 时间管理的七条魔法