2

I am sending JSON data from Android & iPhone apps to my web2py application.

I have also written an 'm' page that is accessible from Android & iPhone platforms that also makes the same JSON calls.

I understand how to determine if the request is from Android or iOS using the web2py utility request.user_agent() .

I have observed these signatures in the http_user_agent:

"Bundle%20name/1.400.130508 CFNetwork/609.1.4 Darwin/13.0.0"  (iOS app)
"Apache-HttpClient/UNAVAILABLE (java 1.4)"                    (android app)

Is there some python module or comprehensive regexp available to determine if a call is coming from a phone app or a from a browser?

ChrisGuest
  • 3,398
  • 4
  • 32
  • 53
  • you can just search for 'iphone' or 'android' in the user agent string – Or Arbel Jun 07 '13 at 05:36
  • If your app is making the HTTP requests, you can programmatically set the user agent to whatever you want – Raghav Sood Jun 07 '13 at 05:41
  • Sorry, to clarify: The two strings that I listed above are what I see when from a an iPhone & an Android app. Do all iPhones and android apps look like those by default? The conditions in my server code that I need to cater for are "App" or "Browser". I don't care that much if android or iphone is in the user agent string. – ChrisGuest Jun 07 '13 at 05:43
  • @RaghavSood that is good advise. But I am actually upgrading the server side logic that supports an App that is already released. – ChrisGuest Jun 07 '13 at 05:46

1 Answers1

1

This is tough, because as some comments point out, app authors can set the user agent string to anything they want. Or don't set it at all, in which case the string will be some default text like Apache-HttpClient/UNAVAILABLE (java 1.4) in your post.

There are many similar questions on the subject, I find this one is especially informative: Parsing HTTP User-Agent string

And that brings us to a possible remedy for you in the form of the httpagentparser python package: https://pypi.python.org/pypi/httpagentparser/

Community
  • 1
  • 1
janos
  • 120,954
  • 29
  • 226
  • 236