我正在编写HTTP WEB SERVER代码。
直到现在我实现了GET, HEAD方法。现在我必须实现 OPTIONS 方法。但这一次客户端的外壳没有收到任何响应。我不明白为什么会这样。请帮助我。我正在发布我的代码,请帮助检测错误。
我的代码
客户
public class Client {
public static void main(String[] args) {
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", "Test Client");
BufferedReader br = null;
OptionsMethod method = new OptionsMethod("http://10.40.55.240:8080/");
try {
int returnCode = client.executeMethod(method);
if(returnCode == 405 ) {
System.out.println("The Options method is not implemented by this URI");
} else {
System.out.println("REACH HERE");
br = new BufferedReader(new InputStreamReader(/*What I put here to get socket InputStream*/);
String readLine;
while((readLine = br.readLine()) != null) {
System.out.println(readLine);
}
}
//System.out.println(returnCode);
} catch(Exception e) {
e.printStackTrace();
} finally {
method.releaseConnection();
if(br != null) {
try {
br.close();
}
catch(Exception e) {}
}
}
}
}
响应客户端的服务器代码
else if(methodName.equals("OPTIONS")) {
System.out.println("GOING TO HANDLE OPTIONS REQUEST");
printStream.print("HTTP/1.1 " + ServerSettings.HTTP_OK + " OK");
printStream.write(EOL);
printStream.print("Date: " + new Date());
printStream.write(EOL);
printStream.print("Allow: OPTIONS, GET, HEAD");
printStream.write(EOL);
printStream.print("Content-Length: 0");
printStream.write(EOL);
}
inputStream.close();
printStream.close();
请帮助我,如何从服务器接收标头。
我应该在客户端的注释部分中放入什么来接收标头。
br = new BufferedReader(new InputStreamReader(/*What I put here to get socket InputStream*/);