我正在为 android 制作一个 java 中的 whois 来训练有关流和 tcp 连接的信息。
但我有一个问题。我有一个 php 脚本,我前段时间写过,我正在尝试在 java 中做同样的事情。
这是我的java代码:
public String consultawhois(String domain,String tld)
{
String domquest = domain + "." + tld;
String resultado = "";
Socket theSocket;
String hostname = "whois.internic.net";
int port = 43;
try {
theSocket = new Socket(hostname, port, true);
Writer out = new OutputStreamWriter(theSocket.getOutputStream());
out.write(domquest + "\r\n");
out.flush();
DataInputStream theWhoisStream;
theWhoisStream = new DataInputStream(theSocket.getInputStream());
String s;
while ((s = theWhoisStream.readLine()) != null) {
resultado = resultado + s + "\n";
}
}
catch (IOException e) {
}
return resultado;
}
服务器的答案不正确,我认为问题在于我发送了错误的查询。我发送的查询是“dominio.com\r\n”,在我的 php whois 代码中,它运行良好。