// Write the headers and body
outputStream.write(bos.toByteArray());
// Read the response
ByteArrayOutputStream response = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length = 0;
while ((length = inputStream.read(buffer)) != -1) {
response.write(buffer, 0, length);
}
response.close();
byte[] mirroredResponse = getMirroredResponse(response.toByteArray());
// Check that the request and response matches
checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
// Close the connection
clientSocket.close();
// Connect to the http server, and do a simple http post, with
// a pause after transmitting the headers
// Connect to the http server, and do a simple http get, with
// a pause in the middle of transmitting the header
clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
outputStream = clientSocket.getOutputStream();
inputStream = clientSocket.getInputStream();
// Write to the socket
bos = new ByteArrayOutputStream();
// Headers
bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
bos.write(CRLF);
// Write the start of the headers, and then sleep, so that the mirror
// thread will have to block to wait for more data to appear
bos. [[#variablee0687e0]] [[#variablee06af60]];
|