以下代码在window下登陆sina和139没有问题,但是在公司的linux服务器上就不行,求解决import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class test { public static void normalLogin(String popServer, String popUser,
String popPassword){
String POP3Server = popServer;
int POP3Port = 110;
Socket client = null;
try {
// 创建一个连接到POP3服务程序的套接字。
client = new Socket(POP3Server, POP3Port);
// 创建一个BufferedReader对象,以便从套接字读取输出。
InputStream is = client.getInputStream();
BufferedReader sockin;
sockin = new BufferedReader(new InputStreamReader(is));
// 创建一个PrintWriter对象,以便向套接字写入内容。
OutputStream os = client.getOutputStream();
PrintWriter sockout;
sockout = new PrintWriter(os, true); // true for auto-flush
// 显示POP3握手信息。
System.out.println("S:" + sockin.readLine()); /*-- 与POP3服务器握手过程 --*/
System.out.print("C:");
String cmd = "user " + popUser;
// 将用户名发送到POP3服务程序。
System.out.println(cmd);
sockout.println(cmd);
// 读取POP3服务程序的回应消息。
String reply = sockin.readLine();
System.out.println("S:" + reply); System.out.print("C:");
cmd = "pass ";
// 将密码发送到POP3服务程序。
//System.out.println(cmd + "*********");
sockout.println(cmd + popPassword);
// 读取POP3服务程序的回应消息。
reply = sockin.readLine();
System.out.println("S:" + reply);
if(reply.contains("+OK")){
System.out.println("success");
}else
System.out.println("密码错误,或未开通POP服务。");
} catch (IOException e) {
System.out.println("连接超时");
} finally {
try {
if (client != null)
client.close();
} catch (IOException e) {
}
}
} /**
* @param args
*/
public static void main(String[] args) {
normalLogin("pop.sina.com","[email protected]","password");
normalLogin("pop.sina.cn","[email protected]","password");
normalLogin("pop.139.com","[email protected]","password");
}}
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class test { public static void normalLogin(String popServer, String popUser,
String popPassword){
String POP3Server = popServer;
int POP3Port = 110;
Socket client = null;
try {
// 创建一个连接到POP3服务程序的套接字。
client = new Socket(POP3Server, POP3Port);
// 创建一个BufferedReader对象,以便从套接字读取输出。
InputStream is = client.getInputStream();
BufferedReader sockin;
sockin = new BufferedReader(new InputStreamReader(is));
// 创建一个PrintWriter对象,以便向套接字写入内容。
OutputStream os = client.getOutputStream();
PrintWriter sockout;
sockout = new PrintWriter(os, true); // true for auto-flush
// 显示POP3握手信息。
System.out.println("S:" + sockin.readLine()); /*-- 与POP3服务器握手过程 --*/
System.out.print("C:");
String cmd = "user " + popUser;
// 将用户名发送到POP3服务程序。
System.out.println(cmd);
sockout.println(cmd);
// 读取POP3服务程序的回应消息。
String reply = sockin.readLine();
System.out.println("S:" + reply); System.out.print("C:");
cmd = "pass ";
// 将密码发送到POP3服务程序。
//System.out.println(cmd + "*********");
sockout.println(cmd + popPassword);
// 读取POP3服务程序的回应消息。
reply = sockin.readLine();
System.out.println("S:" + reply);
if(reply.contains("+OK")){
System.out.println("success");
}else
System.out.println("密码错误,或未开通POP服务。");
} catch (IOException e) {
System.out.println("连接超时");
} finally {
try {
if (client != null)
client.close();
} catch (IOException e) {
}
}
} /**
* @param args
*/
public static void main(String[] args) {
normalLogin("pop.sina.com","[email protected]","password");
normalLogin("pop.sina.cn","[email protected]","password");
normalLogin("pop.139.com","[email protected]","password");
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货