关于flickr获取图片信息的一个java测试程序 大家帮忙看看
package com.xtu.image.google;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
public class TestFlickr {
public static void main(String[] args) throws Exception {
String url = null;
url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=2a74f29247d4837776ec38acc72dfb7d&extras=original_format&per_page=100&format=json&tags=apple";
URLConnection connection = new URL(url).openConnection();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
buffer.append(line);
}
br.close();
isr.close();
is.close();
System.out.println(buffer);
}
}
抛出的异常
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
at com.xtu.image.google.TestFlickr.main(TestFlickr.java:20)
url没错啊 在网页上直接输入能够看到flickr返回的字符串啊。。
------解决方案--------------------
程序没问题 是网络问题