0

Hi I'm developing a HTTP Webrequest send to back end server to retrive information. How We can set the default header so that backend and can recognize where the request come from (android devices, system version...)

something like: request.setHeader = ["User-Agent, "...."]

similar to system.getdefaultUserAgent...

Purpose to help server filter out which request come from mobile devices, which request is not.

Any help is much appreciate. Thanks

Lê Khánh Vinh
  • 2,591
  • 5
  • 31
  • 77

1 Answers1

0

If you are using httpclient

final HttpParams httpParameters = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT);
        httpParameters.setParameter(CoreProtocolPNames.USER_AGENT, "your user agent");
firegloves
  • 5,581
  • 2
  • 29
  • 50
  • Thanks for your help. I know how to set the header. My question is how get the default useragent (contain android devices, OS version...) so that each request will send these info to server? – Lê Khánh Vinh Sep 08 '16 at 15:51
  • oh ok, in my case i have organized myself user agent with these informations, accordingly with UserAgent spec. I don't know ho to get the default one, sorry – firegloves Sep 08 '16 at 15:58
  • so the purpose is to help server to identify request come from android devices. Do you know how can we achieve that? – Lê Khánh Vinh Sep 08 '16 at 16:10
  • I don't understand why do you want to set default useragent over defaultuseragent. i mean: default user agent should be sent automatically, or i'm mistaking? However, setting up a custom useragent let the server to identify it. what is your doubt? – firegloves Sep 08 '16 at 17:04
  • 1
    for my search android does not send user-agent by default (send null instead). Yes the purpose is to identify the request from mobile user and filter out (reject request) those are not (for security reason) – Lê Khánh Vinh Sep 08 '16 at 17:07
  • so adding a custom useragent that respect RFC2616 should solve your problem. Generate it and add to header, no? You can find a simplified explanation of useragent standard here http://stackoverflow.com/questions/2601372/what-is-the-standard-format-for-a-browsers-user-agent-string – firegloves Sep 08 '16 at 17:13
  • Thanks, I 'll try. Do you have sample User-Agent string that we can use? – Lê Khánh Vinh Sep 08 '16 at 17:28