0
我正在寫HTTP WEB SERVER代碼。爲什麼響應頭未顯示在客戶端的shell中?
直到現在我實施了GET,HEAD方法。現在我必須實現OPTIONS方法。但是這次客戶端的shell沒有收到響應。我不明白爲什麼會發生這種情況。請幫助我。我發佈我的代碼,請幫助檢測錯誤。該響應客戶
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();
請幫我
我的代碼
客戶
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) {}
}
}
}
}
服務器代碼,我怎麼能接受的頭球服務器。
我應該在客戶端的註釋部分放入什麼,才能接收標題。
br = new BufferedReader(new InputStreamReader(/*What I put here to get socket InputStream*/);