资源简介
项目需要,一直在学习http相关知识,动手写了一个http服务器的实例,通过该实例可以清楚了解整个http包头及工作原理;(直接能eclipse运行)
代码片段和文件信息
package com.cnryb;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.Header;
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.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import com.sun.net.httpserver.Headers;
public class HttpC {
/**
* @param args
* @throws IOException
* @throws IllegalStateException
*/
public static void main(String[] args) throws IllegalStateException
IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost=new HttpPost(“http://127.0.0.1:8765“);
HttpResponse response=httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
parseResponseEntity(response);
if (entity != null) {
InputStream instreams = entity.getContent();
BufferedReader bf = new BufferedReader(new InputStreamReader(
instreams));
StringBuilder sb=new StringBuilder();
String line = null;
while ((line = bf.readLine()) != null) {
sb.append(line + “\n“);
}
System.out.println(“\nContent:“+sb.toString()+“length=“+sb.length());
//httpPost.abort();
}
}
private static void parseResponseEntity(HttpResponse response) {
if (response != null) {
Header[] headers=response.getAllHeaders();
System.out.println(“Headers:“+“size=“+headers.length);
for(Header header:headers){
System.out.println(“Name=“+header.getName());
System.out.println(“Value=“+header.getValue());
System.out.println(“\n“);
}
System.out.println(“\n“+“Version=“+response.getProtocolVersion()+“\nStatus=“+response.getStatusLine().getStatusCode());
System.out.println(“Local=“+response.getLocale().toString());
HttpEntity entity = response.getEntity();
//entity.
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2657 2014-07-22 16:56 HttpServerAndClient\HttpSer\.classpath
文件 395 2014-07-23 10:32 HttpServerAndClient\HttpSer\.project
文件 598 2013-06-26 16:19 HttpServerAndClient\HttpSer\.settings\org.eclipse.jdt.core.prefs
文件 3296 2014-07-23 10:32 HttpServerAndClient\HttpSer\bin\com\cnryb\HttpC.class
文件 1948 2014-07-23 10:32 HttpServerAndClient\HttpSer\bin\com\cnryb\HttpSer$MyResponseHandler.class
文件 1074 2014-07-23 10:32 HttpServerAndClient\HttpSer\bin\com\cnryb\HttpSer.class
文件 188671 2014-06-24 17:32 HttpServerAndClient\HttpSer\lib\commons-beanutils-1.7.0.jar
文件 232771 2013-06-26 16:42 HttpServerAndClient\HttpSer\lib\commons-codec-1.6.jar
文件 263965 2014-06-24 16:35 HttpServerAndClient\HttpSer\lib\commons-codec-1.9.jar
文件 163151 2013-10-17 21:44 HttpServerAndClient\HttpSer\lib\commons-io-2.1.jar
文件 60686 2013-06-26 16:45 HttpServerAndClient\HttpSer\lib\commons-logging-1.1.1.jar
文件 21776 2013-06-26 16:45 HttpServerAndClient\HttpSer\lib\fluent-hc-4.2.5.jar
文件 433071 2013-10-17 21:44 HttpServerAndClient\HttpSer\lib\httpclient-4.2.3.jar
文件 433368 2013-06-26 16:42 HttpServerAndClient\HttpSer\lib\httpclient-4.2.5.jar
文件 115625 2013-06-26 16:45 HttpServerAndClient\HttpSer\lib\httpclient-cache-4.2.5.jar
文件 227275 2013-06-26 16:45 HttpServerAndClient\HttpSer\lib\httpcore-4.2.4.jar
文件 282160 2014-06-24 16:55 HttpServerAndClient\HttpSer\lib\httpcore-4.3.jar
文件 26477 2014-06-24 16:56 HttpServerAndClient\HttpSer\lib\httpmime-4.2.3.jar
文件 26477 2013-06-26 16:45 HttpServerAndClient\HttpSer\lib\httpmime-4.2.5.jar
文件 17289 2013-10-17 21:44 HttpServerAndClient\HttpSer\lib\jcl-over-slf4j-1.6.6.jar
文件 152797 2014-07-03 11:20 HttpServerAndClient\HttpSer\lib\jdom.jar
文件 39308 2014-06-30 11:48 HttpServerAndClient\HttpSer\lib\json.org.jar
文件 743361 2009-05-28 05:28 HttpServerAndClient\HttpSer\lib\jxl.jar
文件 22545 2014-06-24 16:59 HttpServerAndClient\HttpSer\lib\noggit-0.5.jar
文件 28688 2014-06-24 16:35 HttpServerAndClient\HttpSer\lib\slf4j-api-1.7.6.jar
文件 4090 2014-04-04 13:11 HttpServerAndClient\HttpSer\lib\slf4j-nop-1.7.7.jar
文件 383972 2013-10-17 21:44 HttpServerAndClient\HttpSer\lib\solr-solrj-4.5.1.jar
文件 396 2014-07-03 17:08 HttpServerAndClient\HttpSer\MANIFEST.MF
文件 2512124 2014-07-22 16:55 HttpServerAndClient\HttpSer\poi.jar
文件 2020 2014-07-22 17:01 HttpServerAndClient\HttpSer\src\com\cnryb\HttpC.java
............此处省略14个文件信息
相关资源
- SQL Server课程设计工资管理系统
- 图书管理系统课程设计报告(基于J
- Java语言与面向对象程序设计题解及实
- 深入理解JAVA内存模型.pdf 高清版
- java微信分享源码
- mysql-connector-java-5.1.38.tar.gz
- 基于Java的超市管理系统191276
- 蓝桥杯历年真题及答案java组
- Java咖啡机项目
- Javaee大学生运动会成绩管理系统
- JAVA JSP二手房产系统 源代码 论文
- jogl小导入模型和声音
- 免费:用java编写的网吧计费管理系统
- Java&Tomcat;&Eclipse;安装及配置教程
- java大作业电影票增删改查
- java_仓库管理系统
- 简易论坛javaweb程序
- httpclient-4.5.3完整jar包
- java-家政服务管理系统
- 机房排课系统的设计与实现
- 运动会管理系统J2EE
- httpclient 需要的各种jar包 全版本
- Java常用工具类大全,工作5年精心整理
- java实现文件上传到数据库
- 影院订票java设计
-
msba
se.jarmssqlserver.jarmsutil.jarmysql-co - 基于java的BBS论坛系统源码+数据库文件
- Data Structure and Algorithm Analysis in Java
- 基于Java_Mail的电子邮件收发系统
- java蓝宇快递打印系统综合实验完整版
评论
共有 条评论