服务端模拟http服务请求客户端
try {
InputStream in = req.getInputStream();
int i = -1;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((i = in.read()) != -1) {
out.write(i);
}
String data = out.toString("UTF-8"); //客户端报文
in.close();
out.close();
if (data.indexOf("0100") != -1) {
String path = "/meeting/client/requestdeal"; //客户端请求路径
String host = req.getLocalAddr();
int port = req.getLocalPort();
Socket socket = SocketFactory.getDefault().createSocket(host, port);
OutputStreamWriter streamWriter = new OutputStreamWriter(
socket.getOutputStream(), "utf-8");
BufferedWriter bufferedWriter = new BufferedWriter(streamWriter);
bufferedWriter.write("POST " + path + " HTTP/1.1\r\n");
bufferedWriter.write("Host: " + host + "\r\n");
bufferedWriter.write("Content-Length: " + data.length() + "\r\n");
bufferedWriter.write("Content-Type: application/x-www-form-urlencoded\r\n");
bufferedWriter.write("\r\n");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.write("\r\n");
bufferedWriter.flush();
bufferedWriter.close();
socket.close();
}
return;
}catch(IOException e){
e.printStackTrace();
}
https服务换成:Socket socket = SSLSocketFactory.getDefault().createSocket(host, port);