-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples of authenticating with the X-Authentication-Token header.
- Loading branch information
1 parent
78c0817
commit 69aac64
Showing
16 changed files
with
888 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.whoisxmlapi</groupId> | ||
<artifactId>reverse-whois-api-v2-header-auth</artifactId> | ||
<version>1.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>ReverseWhoisV2HeaderAuthSample</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.2" level="project" /> | ||
</component> | ||
</module> |
129 changes: 129 additions & 0 deletions
129
header-auth/java/src/main/java/ReverseWhoisV2HeaderAuthSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import java.io.BufferedReader; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
|
||
import com.google.gson.*; | ||
|
||
public class ReverseWhoisV2HeaderAuthSample | ||
{ | ||
private String apiKey; | ||
|
||
public static void main(String[] args) throws Exception | ||
{ | ||
ReverseWhoisV2HeaderAuthSample query = | ||
new ReverseWhoisV2HeaderAuthSample(); | ||
|
||
// Fill in your details | ||
query.setApiKey("Your reverse whois api key"); | ||
|
||
try { | ||
String responseStringPost = query.sendPost(); | ||
query.prettyPrintJson(responseStringPost); | ||
|
||
responseStringPost = query.sendPost(true); | ||
query.prettyPrintJson(responseStringPost); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public String getApiKey() | ||
{ | ||
return this.apiKey; | ||
} | ||
|
||
public void setApiKey(String apiKey) | ||
{ | ||
this.apiKey = apiKey; | ||
} | ||
|
||
public String sendPost() throws Exception | ||
{ | ||
return sendPost(false); | ||
} | ||
|
||
// HTTP POST request | ||
public String sendPost(boolean isAdvanced) throws Exception | ||
{ | ||
String userAgent = "Mozilla/5.0"; | ||
String url = "https://reverse-whois-api.whoisxmlapi.com/api/v2"; | ||
|
||
URL obj = new URL(url); | ||
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); | ||
|
||
con.setRequestMethod("POST"); | ||
con.setRequestProperty("User-Agent", userAgent); | ||
con.setRequestProperty("X-Authentication-Token", this.getApiKey()); | ||
|
||
String terms = isAdvanced ? getAdvancedTerms() : getBasicTerms(); | ||
|
||
// Send POST request | ||
con.setDoOutput(true); | ||
DataOutputStream wr = new DataOutputStream(con.getOutputStream()); | ||
wr.writeBytes(terms); | ||
wr.flush(); | ||
wr.close(); | ||
|
||
System.out.println("\nSending 'POST' request to URL : " + url); | ||
|
||
BufferedReader in = new BufferedReader( | ||
new InputStreamReader(con.getInputStream())); | ||
|
||
String inputLine; | ||
StringBuilder response = new StringBuilder(); | ||
|
||
while ((inputLine = in.readLine()) != null) { | ||
response.append(inputLine); | ||
} | ||
in.close(); | ||
|
||
return response.toString(); | ||
} | ||
|
||
private String getAdvancedTerms() | ||
{ | ||
String field = "\"field\": \"RegistrantContact.Name\""; | ||
String term = "\"term\": \"Test\""; | ||
String options = this.getRequestOptions(); | ||
String searchTerms = "{ " + field + ", " + term + " }"; | ||
|
||
String terms = | ||
"\"advancedSearchTerms\": [" + searchTerms + "]"; | ||
|
||
return "{ " + terms + ", " + options +" }"; | ||
} | ||
|
||
private String getBasicTerms() | ||
{ | ||
String exclude = "\"exclude\": [\"pay\"]"; | ||
String include = "\"include\": [\"test\"]"; | ||
String options = this.getRequestOptions(); | ||
|
||
String terms = | ||
"\"basicSearchTerms\": {" + include + ", " + exclude + "}"; | ||
|
||
return "{ " + terms + ", " + options +" }"; | ||
} | ||
|
||
private String getRequestOptions() | ||
{ | ||
return "\"sinceDate\": \"2018-07-16\"," | ||
+ "\"mode\": \"purchase\""; | ||
} | ||
|
||
private void prettyPrintJson(String jsonString) | ||
{ | ||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
|
||
JsonParser jp = new JsonParser(); | ||
JsonElement je = jp.parse(jsonString); | ||
String prettyJsonString = gson.toJson(je); | ||
|
||
System.out.println("\n\n" + prettyJsonString); | ||
System.out.println("----------------------------------------"); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
header-auth/js/reverse_whois_api_v2_header_auth_jquery.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Reverse Whois API 2.0 Header Auth jQuery Search Sample</title> | ||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> | ||
<script type="text/javascript"> | ||
|
||
var url = "https://reverse-whois-api.whoisxmlapi.com/api/v2"; | ||
var apiKey = "Your reverse whois api key"; | ||
|
||
var data_basic = { | ||
"sinceDate": "2018-07-15", | ||
"mode": "purchase", | ||
"basicSearchTerms": { | ||
"include": [ | ||
"cinema", | ||
], | ||
"exclude": [ | ||
"online" | ||
] | ||
} | ||
}; | ||
|
||
var data_advanced = { | ||
"sinceDate": "2018-07-15", | ||
"mode": "purchase", | ||
"advancedSearchTerms": [ | ||
{ | ||
"field": "RegistrantContact.Name", | ||
"term": "Test" | ||
} | ||
] | ||
}; | ||
|
||
function sendQuery(isAdvanced=false) { | ||
$.ajax( | ||
{ | ||
url: url, | ||
type: "post", | ||
data: | ||
JSON.stringify(isAdvanced ? data_advanced : data_basic), | ||
headers: { | ||
"X-Authentication-Token": apiKey | ||
}, | ||
dataType: "json", | ||
success: function(data) { | ||
$("body").append( | ||
(isAdvanced ? "Advanced" : "Basic") + "<br>" | ||
+ "<pre>" +JSON.stringify(data,null,2) +"</pre>"); | ||
} | ||
} | ||
); | ||
} | ||
|
||
$(function() { | ||
sendQuery(); | ||
sendQuery(true); | ||
}); | ||
|
||
</script> | ||
</head> | ||
<body></body> | ||
</html> |
90 changes: 90 additions & 0 deletions
90
header-auth/net/ReverseWhoisApi/ReverseWhoisApiV2HeaderAuth.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{732A829F-F8A4-410C-8BB6-B6F6DD961DB4}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ReverseWhoisApi</RootNamespace> | ||
<AssemblyName>ReverseWhoisApiV2HeaderAuth</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile> | ||
</TargetFrameworkProfile> | ||
<FileAlignment>512</FileAlignment> | ||
<PublishUrl>publish\</PublishUrl> | ||
<Install>true</Install> | ||
<InstallFrom>Disk</InstallFrom> | ||
<UpdateEnabled>false</UpdateEnabled> | ||
<UpdateMode>Foreground</UpdateMode> | ||
<UpdateInterval>7</UpdateInterval> | ||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> | ||
<UpdatePeriodically>false</UpdatePeriodically> | ||
<UpdateRequired>false</UpdateRequired> | ||
<MapFileExtensions>true</MapFileExtensions> | ||
<ApplicationRevision>0</ApplicationRevision> | ||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> | ||
<IsWebBootstrapper>false</IsWebBootstrapper> | ||
<UseApplicationTrust>false</UseApplicationTrust> | ||
<BootstrapperEnabled>true</BootstrapperEnabled> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="ReverseWhoisApiV2HeaderAuthSample.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> | ||
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Web.Extensions" /> | ||
<Reference Include="System.XML" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<BootstrapperPackage Include=".NETFramework,Version=v4.0"> | ||
<Visible>False</Visible> | ||
<ProductName>Microsoft .NET Framework 4.0 %28x86 and x64%29</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.