概述
1.HTTP是以明文方式发送数据的(sniffer可以在局域网内截取内容:使用https安全)2.用于从WWW服务器传输超文本到本地浏览器的传输协议。以TCP/IP为基础的高层协议。
3.现在广泛使用的HTTP/1.1(1.0一个连接只能访问一个服务器的资源,资源下载完断开 再重新链接下载)
4.以http协议手工向服务器发送请求:
先启动tomcat,建立java project 工程名为javaWebByHand 文件名为TestHTTP.java 源代码为:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class TestHTTP {
public static void main(String[] args) throws Exception {
Socket s = new Socket("127.0.0.1", 80); //建立一个到服务器的连接
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));//输出流->转换流(字节处理)->具有缓冲功能
bw.write("GET / HTTP/1.1"); //访问方式 访问资源的名称 基于协议
bw.newLine();
bw.write("Host: 127.0.0.1:80"); //同一个ip下可能有不同的域名
bw.newLine();
bw.write("Content-Type: text/html"); //访问资源的类型
bw.newLine();
bw.newLine();//协议规定
bw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = null;
while((str = br.readLine()) != null) {
System.out.println(str);
}
bw.close();
br.close();
s.close();
}
}
右键 | run as
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: W/"7347-1184876416000"
Last-Modified: Thu, 19 Jul 2007 20:20:16 GMT
Content-Type: text/html
Content-Length: 7347
Date: Tue, 18 Jun 2013 15:37:25 GMT
...网页源代码...
其他
GET 请求获取Request-URI所标识的资源
POST 在Request-URI所标识的资源后附加新的数据
HEAD 请求获取由Request-URI所标识的资源的响应消息报头
PUT 请求服务器存储一个资源,并用Request-URI作为其标识
DELETE 请求服务器删除Request-URI所标识的资源
TRACE 请求服务器回送收到的请求信息,主要用于测试或诊断
CONNECT 保留将来使用
OPTIONS 请求查询服务器的性能,或者查询与资源相关的选项和需求
"100" : Continue "101" : witching Protocols "200" : OK "201" : Created "202" : Accepted "203" : Non-Authoritative Information "204" : No Content "205" : Reset Content "206" : Partial Content "300" : Multiple Choices "301" : Moved Permanently "302" : Found "303" : See Other "304" : Not Modified "305" : Use Proxy "307" : Temporary Redirect "400" : Bad Request "401" : Unauthorized "402" : Payment Required "403" : Forbidden | "404" : Not Found "405" : Method Not Allowed "406" : Not Acceptable "407" : Proxy Authentication Required "408" : Request Time-out "409" : Conflict "410" : Gone "411" : Length Required "412" : Precondition Failed "413" : Request Entity Too Large "414" : Request-URI Too Large "415" : Unsupported Media Type "416" : Requested range not satisfiable "417" : Expectation Failed "500" : Internal Server Error "501" : Not Implemented "502" : Bad Gateway "503" : Service Unavailable "504" : Gateway Time-out "505" : HTTP Version not supported |
最后
以上就是和谐眼神为你收集整理的速成笔记:Hypertext Transfer Protocol的全部内容,希望文章能够帮你解决速成笔记:Hypertext Transfer Protocol所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复