public class FlickrFetchr {
public static final String TAG="FlickrFetchr";
private static final String ENDPOINT="http://api.flickr.com/services/rest/";
private static final String API_KEY="4843d4d381acbac94cf9ee95c907f60b";
private static final String METHOD_GET_RECENT="flickr.photos.getRecent";
private static final String PARAM_EXTRAS="extras";
private static final String EXTRA_SMALL_URL="url_s";
private static final String XML_PHOTO="photo";
byte[] getUrlByte(String urlSpec) throws IOException{
URL url=new URL(urlSpec);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
try{
ByteArrayOutputStream out= new ByteArrayOutputStream();
InputStream in=connection.getInputStream();
if(connection.getResponseCode()!=HttpURLConnection.HTTP_OK){
return null;
}
int byteRead=0;
byte[] buffer=new byte[1024];
while((byteRead=in.read(buffer))>0){
out.write(buffer, 0, byteRead);
}
out.close();
return out.toByteArray();
}finally{
connection.disconnect();
}
}//从指定URL获取原始数据并返回一个字节流数组
public String getUrl(String urlSpec) throws IOException{
return new String(getUrlByte(urlSpec));
}//将返回的结果转换为String
public void fetchItem(){
try{
String url=Uri.parse(ENDPOINT).buildUpon().appendQueryParameter("method", METHOD_GET_RECENT)
.appendQueryParameter("api_key", API_KEY).appendQueryParameter(PARAM_EXTRAS, EXTRA_SMALL_URL)
.build().toString();
String xmlString=getUrl(url);
Log.i(TAG, "Received xml:"+xmlString);
}catch(IOException e){
Log.e(TAG,"Failed to fetch item",e);
}
}//从Flickr获取XML数据,Flickr提供了XML的API,具体方法为http://api.flickr.com/services/rest/? method=flickr.photos.getRecent&api_key=4843d4d381acbac94cf9ee95c907f60b
}
FlickrFetchr为处理网络连接的类,然后使用AsyncTask在后台线程上运行代码,Logcat如下:


------解决思路----------------------
没看明白你想问啥。
既然要翻墙才能访问,那肯定是连不上了。
如果要测试,可以连上VPN再试试。