sandeep kande
sandeep kande

Reputation: 37

How to parse Response from HttpURLConnection object in java

I am trying to validate OTP via 2Factor API but don't know how to parse response data in java code. tested on Postman `

URL url = new URL("https://2factor.in/API/V1/{api_key}/SMS/VERIFY/{session_id}/{otp_entered_by_user}");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();

tested the above API in postman and getting response like this,

{
    "Status": "Success",
    "Details": "OTP Matched"
}

Upvotes: 0

Views: 161

Answers (1)

Vini
Vini

Reputation: 8419

You can get a reference to the input stream from the connection and read the contents. See the link below for an example where it explains both GET and POST requests

https://www.digitalocean.com/community/tutorials/java-httpurlconnection-example-java-http-request-get-post

Upvotes: 1

Related Questions