当前位置: 代码迷 >> Android >> 新手请问:conn.getInputStream();报错
  详细解决方案

新手请问:conn.getInputStream();报错

热度:217   发布时间:2016-05-01 22:06:47.0
新手请教:conn.getInputStream();报错
public InputStream getInputStreamFromUrl(String strUrl) throws Exception {

URL url = new URL(strUrl);
System.out.println("getInputStreamFromUrl " + url);
//打印出来10-16 08:51:21.920: INFO/System.out(1391): getInputStreamFromUrl http://10.0.0.4:8080/mp3/a1.mp3
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream inputStream = conn.getInputStream();//这句报错
System.out.println("getInputStreamFromUrl " + inputStream);
return inputStream;
}
访问Internet权限都已经给了。

哪位高人帮我看看,指导一下,不胜感激!

报错信息如下:
10-16 08:51:21.981: WARN/System.err(1391):  
  at com.download.HttpDownloader.getInputStreamFromUrl(HttpDownloader.java:83)


------解决方案--------------------
是不是需要在
nputStream inputStream = conn.getInputStream();
之前调用
conn.connect()啊?
------解决方案--------------------
public InputStream getDataAsInputStream(List<NameValuePair> params) {
InputStream result = null;
try {
httpRequest = new HttpPost(url);
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = httpClient.execute(httpRequest);

if (200 == httpResponse.getStatusLine().getStatusCode()) {
result = httpResponse.getEntity().getContent();
}
} catch (IOException e) {
Log.e("nimeimei", e.getMessage(), e);
return result;
}
return result;
}


public String intermessage(String str1, String str2) {
String url = "http://10.1.49.137:8080/Good/TestServlet";
HttpConnect httpConnect = new HttpConnect(url, context);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("meetid", str1));
params.add(new BasicNameValuePair("name", str2));
params.add(new BasicNameValuePair("username", LoginActivity.username));
String result = httpConnect.getDataAsString(params);
return result;
}
------解决方案--------------------
探讨

是不是需要在
nputStream inputStream = conn.getInputStream();
之前调用
conn.connect()啊?
  相关解决方案