我正在向Google Advanced rest客户端(ARC)提出请求,我收到以下回复:
date: Sat, 11 Nov 2017 15:33:16 GMT
server: Apache/2.4.18 (Ubuntu)
allow: GET,HEAD,POST,OPTIONS
content-length: 0
content-type: text/html
我必须在java中开发一个TCP套接字,它在应用层使用HTTP发送请求,并发送与google ARC相同的请求。这是我正在使用的代码:
import java.net.*;
import java.io.*;
public class tcpclient {
public static void main(String argv[]) {
if (argv.length == 0) {
System.err.println("java server");
System.exit(1);
}
Socket socket;
InetAddress address;
byte[] mensaje_bytes = new byte[256];
String mensaje = "";
try {
address = InetAddress.getByName(argv[0]);
socket = new Socket(address, 80);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter( socket.getOutputStream(), true);
String message = "OPTIONS / HTTP/1.1\r\n"
+ "Host: somehost\r\n"
+ "User-agent: someuser\r\n"
+ "\r";
out.println( message );
do {
System.out.println(in.readLine());
} while (in.readLine() != null);
}
catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
}
使用上面的代码我收到以下回复:
HTTP/1.1 200 OK
Server: Apache/2.4.18 (Ubuntu)
Content-Length: 0
我想知道为什么我有一些缺少的标题行,例如allow:GET,HEAD,POST,OPTIONS?我做错了什么?