httprequest.java
来自「cmpp的开发的短信端口实例」· Java 代码 · 共 72 行
JAVA
72 行
package com.zhanghao.provision;import java.io.DataInputStream;import java.io.InputStream;import java.io.ByteArrayInputStream;public class HttpRequest { protected DataInputStream inputStream; protected boolean change = false; public HttpRequest() { } public HttpRequest(InputStream inputStream) { this.inputStream = new DataInputStream(inputStream); } public DataInputStream getInputStream() throws Exception{ try{ System.out.println("parseHeaders...."); parseHeaders(); return this.inputStream; } catch(Exception ex){ throw new Exception("取得InputStream失败:"+ex.getMessage()); } } public void parseHeaders() throws Exception{ if(!saveChange()){ try{ String str = inputStream.readLine(); String strTemp = ""; strTemp = strTemp+str; int iLength = 0; while(!str.equals("")){ System.out.println(str); str = inputStream.readLine(); if(str.startsWith("Content-Length:")){ iLength = Integer.parseInt(str.substring(str.indexOf(" ")).trim()); } } byte[] bb = new byte[iLength]; inputStream.readFully(bb,0,iLength); java.io.ByteArrayInputStream binput = new ByteArrayInputStream(bb); inputStream = new DataInputStream(binput); } catch(Exception ex){ throw new Exception("解析HTTP包头失败:"+ex.getMessage()); } } saveChange(); } public boolean saveChange(){ if(!change){ change = true; return false; } return true; } public boolean getChange(){ return this.change; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?