Compare input values
- Print
- PDF
Compare input values
- Print
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
Available in Classic and VPC
This document describes examples of using the Compare CAPTCHA audio input value API.
Compare CAPTCHA audio input value
This section describes API examples that compare the value of the CAPTCHA audio file entered by the user to the actual CAPTCHA value (string or number).
Java
The following is a Java-based sample code for the Compare CAPTCHA audio input value API.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class APIExamCaptchaSkeyResult {
public static void main(String[] args) {
String clientId = "YOUR_CLIENT_ID";//Application's client ID value";
String clientSecret = "YOUR_CLIENT_SECRET";//Application's client secret value";
try {
String code = "0"; // Set to 0 for key issuance and 1 for CAPTCHA audio comparison
String key = "CAPTCHA_KEY"; // Key value received when issuing a CAPTCHA key
String value = "USER_VALUE"; // CAPTCHA value entered by the user
String apiURL = "https://naveropenapi.apigw.ntruss.com/scaptcha/v1/skey?code=" + code +"&key="+ key + "&value="+ value;
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("X-NCP-APIGW-API-KEY-ID", clientId);
con.setRequestProperty("X-NCP-APIGW-API-KEY", clientSecret);
int responseCode = con.getResponseCode();
BufferedReader br;
if(responseCode==200) { // Successful call
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else { // Error occurred
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response.toString());
} catch (Exception e) {
System.out.println(e);
}
}
}
Python
The following is a Python-based sample code for the Compare CAPTCHA audio input value API.
import os
import sys
import urllib.request
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
code = "1"
key = "YOUR_CAPTCHA_KEY"
value = "YOUR_CAPTCHA_VALUE"
url = "https://naveropenapi.apigw.ntruss.com/scaptcha/v1/skey?code=" + code + "&key=" + key + "&value=" + value
request = urllib.request.Request(url)
request.add_header("X-NCP-APIGW-API-KEY-ID",client_id)
request.add_header("X-NCP-APIGW-API-KEY",client_secret)
response = urllib.request.urlopen(request)
rescode = response.getcode()
if(rescode==200):
response_body = response.read()
print(response_body.decode('utf-8'))
else:
print("Error Code:" + rescode)
PHP
The following is a PHP-based sample code for the Compare CAPTCHA audio input value API.
<?php
$client_id = "YOUR_CLIENT_ID";
$client_secret = "YOUR_CLIENT_SECRET";
$key = "CAPTCHA_KEY";
$code = "1";
$value = "USER_VALUE";
$url = "https://naveropenapi.apigw.ntruss.com/scaptcha/v1/skey?code=".$code."&key=".$key."&value=".$value;
$is_post = false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-NCP-APIGW-API-KEY-ID: ".$client_id;
$headers[] = "X-NCP-APIGW-API-KEY: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "status_code:".$status_code."<br />";
curl_close ($ch);
if($status_code == 200) {
echo $response;
} else {
echo "Error content:".$response;
}
?>
JavaScript
The following is a JavaScript-based sample code for the Compare CAPTCHA audio input value API.
var express = require('express');
var app = express();
var client_id = 'YOUR_CLIENT_ID';
var client_secret = 'YOUR_CLIENT_SECRET';
var code = "1";
app.get('/captcha/result', function (req, res) {
var api_url = 'https://naveropenapi.apigw.ntruss.com/scaptcha/v1/skey?code=' + code + '&key=' + req.query.key + '&value=' + req.query.value;
var request = require('request');
var options = {
url: api_url,
headers: {'X-NCP-APIGW-API-KEY-ID':client_id, 'X-NCP-APIGW-API-KEY': client_secret}
};
request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
res.end(body);
} else {
res.status(response.statusCode).end();
console.log('error = ' + response.statusCode);
}
});
});
app.listen(3000, function () {
console.log('http://127.0.0.1:3000/captcha/result?key=캡차키&value=캡차밸류 app listening on port 3000!');
})
C#
The following is a C#-based sample code for the Compare CAPTCHA audio input value API.
using System;
using System.Net;
using System.Text;
using System.IO;
namespace NaverAPI_Guide
{
public class APIExamCaptchaNkeyResult
{
static void Main(string[] args)
{
string code = "0"; // Set to 0 for key issuance and 1 for CAPTCHA audio comparison
string key = "KEY-INPUT"; // Key value received when issuing a CAPTCHA key
string value = "VALUE-INPUT"; // CAPTCHA audio character value entered by the user
string url = "https://naveropenapi.apigw.ntruss.com/scaptcha/v1/skey?code=" + code + "&key=" + key + "&value=" + value;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("X-NCP-APIGW-API-KEY-ID", "YOUR-CLIENT-ID");
request.Headers.Add("X-NCP-APIGW-API-KEY", "YOUR-CLIENT-SECRET");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string status = response.StatusCode.ToString();
if(status == "OK")
{
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
string text = reader.ReadToEnd();
Console.WriteLine(text);
}
else
{
Console.WriteLine("Error occurrence=" + status);
}
}
}
}
Was this article helpful?