简体   繁体   中英

Distinguish between http mobile browser and mobile app request

I read some post like this , this and some other without response. However seems I found here the solution for IOS device.

I need to reject any http request from any app of any device and process only request from web browser, so the mainly question is:

There is a definitive way to tell if an HTTP request is made from a mobile app or from a web browser?

Thanks

Example: I receive all http request start from mobile/tablet (I'm developing application behind wifi hotspot), so i process request from Facebook App, Whatsup App and browser. I have to reject request from Facebook and Whatsup and process only request from browser. Apps User-agent seems the same of native device browser.

You can do one thing. Set custom user-agent from application side.

You can set custom user-agent in both android and iphone during web-service call request.

For Android

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android");

For Iphone

NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] 
                                       initWithURL:[NSURL URLWithString:[yourURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSString *userAgent = "iphone";
[urlRequest setValue:userAgent forHTTPHeaderField:@"User-Agent"];

Check in request header if user-agent is "android" or "iphone" is from application and other-wise from browser.

you can check for the user-agent in the request header, I remember mobile browsers send a different value for user-agent and desktop browsers a different one. Just debug user-agent header and validate based on the values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM