在Android中,InputStream使用HttpUrlConnection返回0

时间:2010-10-14 17:27:27

标签: android httpurlconnection

我在Android应用中使用HttpUrlConnection进行URLURL在浏览器中给我回复,但在下面的代码中InputStream回复为0。为什么呢?

这是我的代码:

URL url = new URL("https://certify.securenet.com/payment.scrnt");

HttpURLConnection httpCon = (HttpURLConnection)url.openConnection();
InputStream in = httpCon.getInputStream();

byte content[] = new byte[in.available()];
in.read(content, 0, content.length);
String receivedString = new String(content);
Log.d("Received String", receivedString)

2 个答案:

答案 0 :(得分:2)

如果您不需要安全连接,请尝试在网址中将“https://”更改为“http://”。
或者尝试更改为HttpsUrlconnection而不是HttpUrlconnection。

答案 1 :(得分:0)

我认为您必须使用HttpsUrlConnection来处理 https 计划的网址。