Reputation: 37
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
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
Upvotes: 1