Transfer-Encoding = "Transfer-Encoding" ":" 1#transfer-coding
Chunked-Body = *chunk
last-chunk
trailer
CRLF
chunk = chunk-size [ chunk-extension ] CRLF
chunk-data CRLF
chunk-size = 1*HEX
last-chunk = 1*("0") [ chunk-extension ] CRLF
chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
chunk-ext-name = token
chunk-ext-val = token | quoted-string
chunk-data = chunk-size(OCTET)
trailer = *(entity-header CRLF)
public class Main {
/**
* @param args
*/
public static final int CR = 13; // <US-ASCII CR, carriage return (13)>
public static final int LF = 10; // <US-ASCII LF, linefeed (10)>
public static void main(String[] args) throws Exception{
Socket socket = new Socket("localhost",8080);
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
//send requestline
out.write("POST /web/Hello HTTP/1.1".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
//send request header
out.write("Host:localhost:8080".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
out.write("Accept-Encoding:gzip,deflate".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
out.write("Transfer-Encoding:chunked".getBytes());// 指定transfer-encodeing为chunked方式
out.write(CR & 0xFF);
out.write(LF & 0xFF);
out.write("Content-Type:application/x-www-form-urlencoded;charset=utf-8".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
// CRLF between headers and entity
out.write(CR & 0xFF);
out.write(LF & 0xFF);
/*
* send chunked data
*/
//send the first chunked data:hello,world
//the first chunked data's size : 11
out.write("B".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
//the first chunked data's content : hello,world
out.write("hello,world".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
//send the second chunked data:tony
//the first chunked data's size : 4
out.write("4".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
//the first chunked data's content : hello,world
out.write("tony".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
//send the chunked data end flag
out.write("0".getBytes());
out.write(CR & 0xFF);
out.write(LF & 0xFF);
//send CRLF
out.write(CR & 0xFF);
out.write(LF & 0xFF);
out.flush();
//
byte[] buffer = new byte[512];
ByteArrayOutputStream bufferStream = new ByteArrayOutputStream();
int len = -1;
while((len = in.read(buffer)) != -1){
bufferStream.write(buffer,0,len);
}
System.out.println(new String(bufferStream.toByteArray()));
socket.close();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有