这是我使用图形 API 测试 facebook 数据收集的示例程序。在我的整个项目中,我无法找到错误的根本原因。第一次从程序中收集数据。但第二次它显示 ssl 异常。
public class Testing {
public static void main(String[] args) throws IOException {
// Make a URL to the web page
boolean flag=false;
int count=0;
while(true)
{
count++;
if(count==2)
{
flag=false;
}
System.out.println(new Date());
URL url = new URL("https://graph.facebook.com/fql?q=select+message,post_id,created_time,actor_id,attachment,comments,created_time,impressions,likes,message_tags,place,share_count+from+stream+where+source_id+in(select+page_id+from+page+where+username=%27ATT%27)+and+created_time>1368439594&access_token=[HERE STANDS MY ACCESSTOKEN]");
System.out.println(new Date());
// Get the input stream through URL Connection
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
// Once you have the Input Stream, it's just plain old Java IO stuff.
// For this case, since you are interested in getting plain-text web page
// I'll use a reader and output the text content to System.out.
// For binary content, it's better to directly read the bytes from stream and write
// to the target file.
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
// read each line and write to System.out
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
}
请指导我解决这个问题。
错误:
线程“main”中的异常 javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接 在 sun.security.ssl.SSLSocketImpl.readRecord(未知来源) 在 sun.security.ssl.SSLSocketImpl.performInitialHandshake(未知来源) 在 sun.security.ssl.SSLSocketImpl.startHandshake(未知来源) 在 sun.security.ssl.SSLSocketImpl.startHandshake(未知来源) 在 sun.net.www.protocol.https.HttpsClient.afterConnect(未知来源) 在 sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(未知来源) 在 sun.net.www.protocol.http.HttpURLConnection.getInputStream(未知来源) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(未知来源) 在 span.com.Testing.main(Testing.java:28) Caused by: java.io.EOFException: SSL peer shutdown 不正确 在 sun.security.ssl.InputRecord.read(未知来源) ... 9 更多
最佳答案
您的 URL 是 HTTPS URL,这意味着它使用 SSL 但您尝试使用 URLConnection
打开连接。要打开 HTTPS URL,您应该使用 HttpsURLConnection
:
final HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
有了这个改变,它对我有用。 ;)
关于java - Facebook Graph API SSL 套接字握手异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30214224/