问题描述
我试图用一个Android应用程序,以获得一个网站的数据。
I'm trying to get data from a website with an android application.
下面是我的code:
URL url = new URL("http://www.google.com/ig/api?weather=Schriesheim,Germany");
URLConnection uCon = url.openConnection();
iStream = uCon.getInputStream();
该方法的getInputStream()返回我一个IOException,我已经尝试过很多事情找到在互联网上,但没有什么工作。
顺便说一句,我试着在Java应用程序中这code和它的工作,所以我认为这个问题是在我的Android设置。
The method getInputStream() returns me an IOException, I already tried lots of things find on Internet, but nothing is working.By the way, I tried this code in a Java application and it worked so I assume this the problem is in my Android settings.
我已经在我的Manifest.xml添加这些行:
I already add these lines in my Manifest.xml :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
我使用Eclipse和运行的Archlinux 64。
任何想法?
I'm using Eclipse and running Archlinux x64.Any idea ?
感谢您。
推荐答案
您可以试试这个功能得到互联网数据
You can try this function for get data from internet
public static String get(String from) {
try {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(from);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) return EntityUtils.toString(resEntityGet);
} catch (Exception e) {
Log.e("GET", e.toString());
}
return null;
}
这篇关于IOException,使用的URLConnection和的getInputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!