我目前有以下 HTTP 客户端。每次我尝试向服务器发送第二个请求时,都会出现以下错误:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: printStackTrace
at clientpersistent.ClientPersistent.main(ClientPersistent.java:84)
Java Result: 1
这是客户端代码:
Socket ClientSocket = new Socket(ClientHostName,1991);
/*We simply open the input and output buffers for our connect
* We do this so that we can read and write to the connection between our client and server
*/
BufferedReader InputClient = new BufferedReader(new InputStreamReader(ClientSocket.getInputStream()));
DataOutputStream OutputClient =new DataOutputStream(ClientSocket.getOutputStream());
OutputClient.writeBytes("GET /my.html HTTP/1.0\r\n");
OutputClient.writeBytes("Host: localhost:1991\r\n");
OutputClient.writeBytes("Connection: Keep-Alive\r\n");
OutputClient.writeBytes("Cache-Control: max-age=0\r\n");
OutputClient.writeBytes("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
OutputClient.writeBytes("User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36\r\n");
OutputClient.writeBytes("Accept-Encoding: gzip,deflate,sdch\r\n");
OutputClient.writeBytes("Accept-Language: en-US,en;q=0.8\r\n");
OutputClient.writeBytes("\r\n");
/*Here we are simply displaying to the screen the response from the server for the flie we asked for*/
String s;
while ((s = InputClient. readLine()) != null)
{
System.out.println(s);
}
Thread.sleep(1000);
//ERROR HAPPENS HERE!!
OutputClient.writeBytes("GET /download.jpg HTTP/1.0\r\n");
OutputClient.writeBytes("Host: localhost:1991\r\n");
OutputClient.writeBytes("Connection: Keep-Alive\r\n");
OutputClient.writeBytes("Cache-Control: max-age=0\r\n");
OutputClient.writeBytes("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
OutputClient.writeBytes("User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36\r\n");
OutputClient.writeBytes("Accept-Encoding: gzip,deflate,sdch\r\n");
OutputClient.writeBytes("Accept-Language: en-US,en;q=0.8\r\n");
OutputClient.writeBytes("\r\n");
while ((s = InputClient.readLine()) != null)
{
System.out.println(s);
}
//Here we close the the read and write buffers and the socket connection
OutputClient.close();
InputClient.close();
ClientSocket.close();