获取url.getContent()时出现问题 [英] Problem in getting url.getContent()

查看:1662
本文介绍了获取url.getContent()时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手头有问题。

我有一个URL,当我启动连接到这个URL并执行url.getContent()时。
响应的类型为 sun.net.www.protocol.http.HttpURLConnection $ HttpInputStream

I have a URL, And when i initiate the connect to this url and execute url.getContent(). The response is of type sun.net.www.protocol.http.HttpURLConnection$HttpInputStream

我尝试将输出分配给 HttpURLConnectionHttpInputStream h = url.getContent()。但我没有成功。
我将相应的库导入代码,但仍然没有运气。

I tried to assign the output to HttpURLConnectionHttpInputStream h = url.getContent(). But i was unsuccessful. I imported corresponding libraries to code, but still no luck.

如果我在eclipse中检查url.getContent(),它还会显示变量thei $ 0在它。

If i inspect the url.getContent() in eclipse, it also shows the variable thei$0 in it.

我只需要这个$ 0的URL。但到目前为止我无法撤回它。

All i need is a URL in this$0. But till now i am unable to retreive it.

在这个$ 0中有一个变量名称url,我正在尝试获取它。

In this$0 there is a variable names url and i am trying to fetch it.

我也很难理解这个$ 0和hoe来检索它。

I also have hard time understand this$0 and hoe to retrieve it.

使用流后我得到一些不可读的输出

After using the streams i get some non readable output

问候
Dheeraj Joshi

Regards Dheeraj Joshi

推荐答案

你应该使用 openStream 方法。

代码段:

InputStream in = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader());
String line = reader.readLine();

如果输出不是可读的字符串格式,请使用:

If the output is not in a readable string format, then use:

InputStream in = url.openStream();
byte[] buffer = new byte[512];
int bytesRead = in.read(buffer);

这篇关于获取url.getContent()时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆