Scan a URL for Safety Threats in Java
Since URLs are a large part of how we move around cyberspace, it makes sense that we would want to ensure the security of every link that our employees or users interact with. You can simplify this task by utilizing the following API in Java; it will scan any URL to assess the risk of it being infected with a safety threat such as malware, unwanted software, or a phishing attempt.
To use this Cloudmersive API, we first need to install the Maven SDK by adding a reference to the repository in pom.xml:
repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, we can add a reference to the dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.90</version>
</dependency>
</dependencies>
Now that we’ve completed the installation, we can add the imports and call the function with the following code:
// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.DomainApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");DomainApi apiInstance = new DomainApi();
UrlSafetyCheckRequestFull request = new UrlSafetyCheckRequestFull(); // UrlSafetyCheckRequestFull | Input URL request
try {
UrlSafetyCheckResponseFull result = apiInstance.domainSafetyCheck(request);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DomainApi#domainSafetyCheck");
e.printStackTrace();
}
Your returned response will indicate if the URL is clean and the threat type (if present). To retrieve your personal API key, register for a free account on the Cloudmersive website; this will grant you access to 800 monthly calls across our library of APIs.