Is there a standard header for mobile http requests that specifies device type, os version, app version etc?

StackOverflow https://stackoverflow.com/questions/23326917

Pergunta

I am creating a json API for my mobile clients and was wondering if there's already a standard like User-Agent to send information like

  • device type
  • device os
  • app version

Or any other thing my server would like to know about the client device...

Since mobile usage has grown so popular, it seems reasonable if there was a standard of some sort.

  1. Should I request my clients to send all this information in User-Agent header (even though the requests are not being sent by browsers) ?
  2. Should I create custom headers for these type of fields and perhaps prefix them with X-MyApp-... ?

I know I can chose to use any of the methods I like since it's my api and I can decide whatever I want, but i'm curious if there's any industry standard in that matter.

Thanks

Foi útil?

Solução

There is no standard HTTP header for conveying device-specific information. I can't speak to what information the Android platform exposes, but I know that any iOS app that uses NSURLConnection to make HTTP requests uses a customised User-Agent string which is of the following format:

<App Name>/<App Version> CFNetwork/<CFNetwork version> Darwin/<kernel version>

There's a pretty handy list of CFNetwork versions that you could use to try to determine what version of iOS is running on the device making the calls. However, it's worth noting that sometimes the CFNetwork and kernel versions don't change between iOS releases. For example, CFNetwork/609.1.4 Darwin/13.0.0 is used by iOS 6.1.2, 6.1.3, and 6.1.4.

Your best bet is to define your own X-Header and transmit exactly the information you need. Prefixing the X-Header will reduce the likelihood of a header collision with another app, but since it's trivial to add a header to a request, you can't rule out spoofing or invalid data.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top