Skip to content

Commit

Permalink
Corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisxmlapi committed Jul 17, 2018
1 parent 2ae33d6 commit 0c8a9a0
Show file tree
Hide file tree
Showing 32 changed files with 957 additions and 711 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Using the Domain Availability API web service

[Domain Availability API](https://www.whoisxmlapi.com/domain-availability-api.php)
checks whether a domain name is available for registration for nearly all of
the TLDs.
checks whether the specified domain name is available for registration for
nearly all of the TLDs.

Here you'll find examples of using the API implemented in multiple languages.
Here you'll find examples of querying the API implemented in multiple
languages.

You'll need a
[WhoisXmlApi account](https://www.whoisxmlapi.com/user/create.php) to
authenticate.

This API also supports
[API key authentication](https://www.whoisxmlapi.com/user/management.php#api-key-management).

Please, refer to the
[Domain availability API User Guide](https://www.whoisxmlapi.com/domain-availability-api-guide.php)
for info on input parameters, request/response formats, authentication
Expand Down
2 changes: 1 addition & 1 deletion apikey/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.whoisxmlapi</groupId>
<artifactId>domainavailability-apikey-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>

<dependencies>
<dependency>
Expand Down
96 changes: 63 additions & 33 deletions apikey/java/src/main/java/DomainAvailabilityApiKeySample.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,34 @@
import org.json.JSONException;
import org.json.JSONObject;

public class DomainAvailabilityApiKeySample {
public class DomainAvailabilityApiKeySample
{
private Logger logger =
Logger.getLogger(DomainAvailabilityApiKeySample.class.getName());

private Logger logger = Logger.getLogger(DomainAvailabilityApiKeySample.class.getName());

public static void main(String[]args) {
public static void main(String[]args)
{
new DomainAvailabilityApiKeySample().getSimpleDomainUsingApiKey();
}

private void getSimpleDomainUsingApiKey() {
private void getSimpleDomainUsingApiKey()
{
String domainName = "google.com";

String username = "Your domain availability api username";
String apiKey = "Your domain availability api apiKey";
String secretKey = "Your domain availability api secretKey";
String apiKey = "Your domain availability api key";
String secretKey = "Your domain availability api secret key";

getDomainNameUsingApiKey(domainName, username, apiKey, secretKey);
}

private String executeURL(String url) {
private String executeURL(String url)
{
HttpClient c = new HttpClient();
System.out.println(url);
HttpMethod m = new GetMethod(url);
String res = null;

try {
c.executeMethod(m);
res = new String(m.getResponseBody());
Expand All @@ -44,70 +49,95 @@ private String executeURL(String url) {
} finally {
m.releaseConnection();
}

return res;
}

public void getDomainNameUsingApiKey(String domainName, String username, String apiKey, String secretKey) {
String apiKeyAuthenticationRequest = generateApiKeyAuthenticationRequest(username, apiKey, secretKey);
public void getDomainNameUsingApiKey(
String domainName,
String username,
String apiKey,
String secretKey
)
{
String apiKeyAuthenticationRequest =
generateApiKeyAuthenticationRequest(username, apiKey, secretKey);

if (apiKeyAuthenticationRequest == null) {
return;
}

StringBuilder sb = new StringBuilder();
sb.append("http://www.whoisxmlapi.com/whoisserver/WhoisService?");
sb.append(apiKeyAuthenticationRequest);
sb.append("&cmd=GET_DN_AVAILABILITY");
sb.append("&domainName=");
sb.append(domainName);
String domName = "";
try {
domName = URLEncoder.encode(domainName, "UTF-8");
} catch (Exception e) {
logger.log(Level.SEVERE, "an error occurred", e);
}

String url = sb.toString();
String url = "https://www.whoisxmlapi.com/whoisserver/WhoisService?"
+ apiKeyAuthenticationRequest
+ "&cmd=GET_DN_AVAILABILITY"
+ "&domainName=" + domName;

String result = executeURL(url);
if (result != null) {
logger.log(Level.INFO, "result: " + result);
}
}

private String generateApiKeyAuthenticationRequest(String username, String apiKey, String secretKey) {
private String generateApiKeyAuthenticationRequest(
String username,
String apiKey,
String secretKey
)
{
try {
long timestamp = System.currentTimeMillis();

String request = generateRequest(username, timestamp);
String digest = generateDigest(username, apiKey, secretKey, timestamp);
String digest =
generateDigest(username, apiKey, secretKey, timestamp);

String requestURL = URLEncoder.encode(request, "UTF-8");
String digestURL = URLEncoder.encode(digest, "UTF-8");

String apiKeyAuthenticationRequest = "requestObject="+requestURL+"&digest="+digestURL;
return apiKeyAuthenticationRequest;
return "requestObject=" + requestURL + "&digest=" + digestURL;
} catch (Exception e) {
logger.log(Level.SEVERE, "an error occurred", e);
}
return null;
}

private String generateRequest(String username, long timestamp) throws JSONException {
private String generateRequest(String username, long timestamp)
throws JSONException
{
JSONObject json = new JSONObject();
json.put("u", username);
json.put("t", timestamp);
String jsonStr = json.toString();
byte[] json64 = Base64.encodeBase64(jsonStr.getBytes());
String json64Str = new String(json64);
return json64Str;

return new String(json64);
}

private String generateDigest(String username, String apiKey, String secretKey, long timestamp) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append(username);
sb.append(timestamp);
sb.append(apiKey);
private String generateDigest(
String username,
String apiKey,
String secretKey,
long timestamp
)
throws Exception
{
String sb = username + timestamp + apiKey;

SecretKeySpec secretKeySpec =
new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacMD5");

SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacMD5");
Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm());
mac.init(secretKeySpec);

byte[] digestBytes = mac.doFinal(sb.toString().getBytes("UTF-8"));
String digest = new String(Hex.encodeHex(digestBytes));
return digest;
byte[] digestBytes = mac.doFinal(sb.getBytes("UTF-8"));

return new String(Hex.encodeHex(digestBytes));
}
}
71 changes: 48 additions & 23 deletions apikey/js/domain_availability_apikey.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<script type="text/javascript">
var domain = "google.com";
var key = "Your domain availability api apiKey";
var secret = "Your domain availability api secretKey";
var username = "Your domain availability api username";
<!DOCTYPE html>
<html>
<head>
<title>Domain Availability API jQuery Api Key Search Sample</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<script type="text/javascript">

$(function () {
var time = (new Date()).getTime();
var req = btoa(unescape(
encodeURIComponent(JSON.stringify({t:time,u:username}))));
var digest = CryptoJS.HmacMD5(
username+time+key,secret).toString(CryptoJS.enc.Hex);
$.ajax({
url: "http://www.whoisxmlapi.com/whoisserver/WhoisService",
dataType: "json",
data: {cmd: "GET_DN_AVAILABILITY", requestObject: req, digest: digest,
domainName: domain, outputFormat: "JSON"},
complete: function(data) {
$("body").append("<pre>" + data.responseText+"</pre>");
}
var apiUrl = "https://www.whoisxmlapi.com/whoisserver/WhoisService";
var domain = "google.com";
var username = "Your domain availability api username";
var key = "Your domain availability api key";
var secret = "Your domain availability api secret key";

$(function() {
var time = (new Date()).getTime();

var params = {
t: time,
u: username
};

var data = JSON.stringify(params);
var req = btoa(unescape(encodeURIComponent(data)));
var digest = CryptoJS.HmacMD5(username + time + key, secret)
.toString(CryptoJS.enc.Hex);

$.ajax(
{
url: apiUrl,
dataType: "json",
data: {
cmd: "GET_DN_AVAILABILITY",
requestObject: req,
digest: digest,
domainName: domain,
outputFormat: "JSON"
},
complete: function(data) {
$("body").append(
"<pre>" + JSON.stringify(data, null, 2)+"</pre>");
}
}
);
});
});
</script>

</script>
</head>
<body></body>
</html>
Loading

0 comments on commit 0c8a9a0

Please sign in to comment.