Change HTTP User Agent

5

When an Android app sends a post to a Web server (type for a PHP page), this page receives an HTTP-UserAgent type "Apache-HttpClient / UNAVAILABLE (Java 1.4)".

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

    
asked by anonymous 16.10.2014 / 16:28

1 answer

2

Although in your question you mean that you want to limit the use of PHP to a particular application, where for the purpose you should implement an authentication system, it follows how to pass a UA custom:

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);
    
16.10.2014 / 17:08