我正在通过从 cURL 发送请求来测试我的 Web 服务器。当我发送此命令时:
curl -H "_ADD_CLASS*21112*ab*https://somewebsite" 127.0.0.1:12345
到我的服务器,我在我的 Java Socket 中得到这个
GET / HTTP/1.1
User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
Host: 127.0.0.1:12345
Accept: */*
_ADD_CLASS*21112*ab*https://somewebsite
这是我所期待的。
但是,当我使用 cURL 将此请求发送到我的服务器时,由于某种原因它不会发送标头:
curl -H "REMOVE_CLASS*21111*a" 127.0.0.1:12345
GET / HTTP/1.1
User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
Host: 127.0.0.1:12345
Accept: */*
"" (as shown in java)
知道为什么第二个请求显示为“”吗?这是一些代码:
private static void handleRequest(Socket socket) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String socketData = null;
String[] commands;
while (br.ready()) {
socketData = br.readLine();
//parse command
if (socketData.compareTo("") == 0) {
//Log error
break;
}else {
if (socketData.charAt(0) != '_') continue;
commands = socketData.split("\\*");
if (commands[0].compareTo("_ADD_CLASS") == 0) {
//syntax is ADD_CLASS*CRN*TOKEN*WEB_ADDRESS
socket.close();
addClass(commands[1], commands[2], commands[3]);
break;
}else if(commands[0].compareTo("_REMOVE_CLASS") == 0) {
//syntax is REMOVE_CLASS*CRN*TOKEN
socket.close();
removeClass(commands[1], commands[2]);
break;
}else if(commands[0].compareTo("_UPDATE_TOKEN") == 0) {
//syntax is UPDATE_TOKEN*OLD_TOKEN*NEW_TOKEN
socket.close();
updateDeviceToken(commands[1], commands[2]);
break;
}else {
//log error
}
}
}
socket.close();
}