Parse User-Agents and Identify Robots in Java

Cloudmersive
2 min readOct 2, 2020

To help you improve your organization’s online security, this Cloudmersive API will allow you to parse HTTP User-Agent strings. This action will retrieve all device information, operating system, and browser data, as well as identifying whether the input user-agent is a robot.

Our first step in implementing this API is to install our SDK and add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then, we can add a reference to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>

After this, we can call our function, UserAgentParse:

// 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.UserAgentApi;
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");
UserAgentApi apiInstance = new UserAgentApi();
UserAgentValidateRequest request = new UserAgentValidateRequest(); // UserAgentValidateRequest | Input parse request
try {
UserAgentValidateResponse result = apiInstance.userAgentParse(request);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling UserAgentApi#userAgentParse");
e.printStackTrace();
}

Now, you can ensure that your online programs are secure, and you can track and monitor what users access your website. You can retrieve your free API Key from the Cloudmersive website. This will give you access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.