Change HTTP User Agent

Asked

Viewed 267 times

5

When an Android app sends a post to a web server (like a PHP page), this page receives an HTTP-Useragent type "Apache-Httpclient/UNAVAILABLE (Java 1.4)".

I wonder if you have a solution to change this value on the Android side? The goal would be to prevent another app trying to connect on this page. So, with a specific value, it would be possible for PHP to test who calls it.

  • 1

    If the goal is to prevent other accesses that are not made by the App, I believe you can send an extra header parameter without changing the User-Agent. For this, it depends on which class you are using to make the connection.

  • You must be using the Httpclient from Apache. But that gives, until you can change the Useragent, as demonstrated here in the documentation. But for the purposes that you want to use I believe that is not the best option, because from what I understand you want to do some kind of "Authentication" validating this field on the server, I will not tell you anything, but if you search.

1 answer

2

Although in your question you hint that you want to limit the use of PHP to a particular application, where you should implement an authentication system, follow how to pass a UA customized:

private String url = "http://example.com/";
private String ua = "A minha UA toda bonita";

private HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", ua);
  • Cool, I’ll test that. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.