如何解决发生错误时,请阅读google电子表格
| 当我的程序运行到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();
}
}
解决方法
您是代理人吗?您可能需要设置Java代理,此处的说明为http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。