以下代码在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.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");
}}
解决方案 »
- 听说android5.0不用java开发了是不是真的呀 求解?????万分感谢
- 入职一段时间了有点迷茫....大牛们谈谈自己是怎么走过来的把...
- 谁有基础的网站开发实例教程吗?
- ssh架构里的拦截器,一般什么情况下用呢?
- -----请问哪里有WebService的视频教程,我是初学者,希望大家多多帮忙,不要西安交通大学的。
- 有石家庄的做java开发的吗?我想拜师学艺
- 何以<bean:message>显示的中文全是问号?
- 使用db2java.jar,怎么项目中有的查询能查到数据,有的查询查不到数据(应该能查出)呢?
- hibernate映射字段类型的问题!
- struts的例子运行不起来!
- java web整合开发王者归来 这本书怎么样?
- 三种常见的Java应用性能挑战
linux服务器没有正常的访问外网,无法解析DNS ping pop.sina.com试试看
System.out.println("连接超时");
别把异常给忽略吞食了,这样无法查错的System.out.println("连接超时");
e.printStackTrace();