How to Parse an HTTP User-Agent String; Identify Robots using Java

User-agent request headers are designed so that network peers/servers can easily identify their various component parts. If you want to retrieve User-Agent information for your own purposes, we have an API that can help: our Parse HTTP User-Agent String API will return a haul of information about any given user-agent, including — importantly — whether that user-agent is a robot. Below I’ve included a full example response body (JSON) showing the various components returned by this API call:

You can easily take advantage of this API using the ready-to-run Java code examples included below to structure your API call. It’s completely free to use — just register a free account on our website (this account will come with a limit of 800 API calls per month and zero additional commitments; perfect for smaller projects and startups).

To start installing the API client, let’s first add a reference to the pom.xml repository:

And then let’s add one to the pom.xml dependency:

Now let’s shift focus over to the controller and add the following imports:

Lastly, let’s include the final code block to call the function. The comments indicate where to authenticate your Cloudmersive API key:

When we pass our parse request through the function, we should structure it like so:

With that, you’re all finished — no more code required. Nice & easy!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

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