Sujit
Sujit

Reputation: 10632

InputStream returns 0 with HttpUrlConnection in Android

I'm doing a HttpUrlConnection in Android application with an URL. The URL is giving me response in the browser but in the code below InputStream response is 0. Why?

Here's my code:

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)

Upvotes: 0

Views: 1542

Answers (2)

BlackDragonBE
BlackDragonBE

Reputation: 302

Try changing from "https://" to "http://" in the URL if you don't need a secure connection.
Or try changing to HttpsUrlconnection instead of HttpUrlconnection.

Upvotes: 2

brambury
brambury

Reputation: 286

I suppose that you have to use HttpsUrlConnection for URLs with https scheme.

Upvotes: 0

Related Questions