当我的程序运行到service.getFeed(metafeedUrl,SpreadsheetFeed.class)
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:503)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
at GdataTest.main(GdataTest.java:55)
我不知道如何解决这个问题。 请帮帮我,我是中国人, 所以我的英语不好,我希望你知道我的意思。
这是我的代码:
try {
final URL url = new URL(
"https://www.google.com/accounts/ClientLogin");
final URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
final DataOutputStream cgiInput = new DataOutputStream(
urlConn.getOutputStream());
String content = null;
content = "accountType=" + "HOSTED" + "&Email=" + email
+ "&Passwd=" + password + "&service=" + "wise" + "&source="
+ applicationName;
cgiInput.writeBytes(content);
cgiInput.flush();
cgiInput.close();
if (urlConn instanceof HttpURLConnection) {
final boolean status = ((HttpURLConnection) urlConn)
.getResponseCode() == 200;
if (status) {
System.out.println("i'm in");
SpreadsheetService service = new
SpreadsheetService(applicationName);
URL metafeedUrl = new
URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
for (int i = 0; i < spreadsheets.size(); i++) {
SpreadsheetEntry entry = spreadsheets.get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:-1)
你是代理人吗?您可能需要在此处设置java代理,说明http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html