Make iOS / Android HTTP request looks like it comes from PC Browser? - android

Is it possible to make HTTP request from iOS / Android Application to look for the Server exactly the same as if it came from PC Browser?
So, it would be impossible for the Server to detect that it is not actually from PC but from Mobile.

Yes, you can alter the User Agent header to make it look like the request was made by f.ex Internet Explorer.
Here is some clues on how to accomplish this on Android:
Android HTTP User Agent
iOS:
Change User-Agent and remove App Name and defaults iOS

Set the user agent on the request to other than the default to fool the server into thinking the request is coming from other than a device. One list of user agents is at http://www.useragentstring.com.

Related

Res.redirect() vs res. Json(). Server for web and mobile

I am new to web development. I had a web project with EJS templating. It redirects directly from the server. Using res.redirect() . I want to create a server for web and mobile both.
Question is... When i use res.json() it sends JSON data to client side. Can work for both.
It is possible to use res.redirect() for both. Web and mobile.
Pros and cons of res.rediret and res.json
Please explain. I appreciate your suggestions in adv. Thanks.
It is possible to use res.redirect() for both. Web and mobile.
If you mean can you use res.redirect() as an alternative to res.json() then the answer is NO. res.redirect() is not an alternative to res.json. res.redirect() only sends a code and a URL back to the client, there is no data in the response. You will still need to use res.json or res.send to get the data you need. Every time you use res.redirect() you are sending a response to the client telling them to make a brand new request to another location. You're not sending any real data. The android app will not get any content till you use res.json or res.send. Redirects just tell the client go get the data from somewhere else.
Below are example responses to an android app when the server uses res.json and res.redirect
res.redirect("/user")
//Response to Android app
302 /user
The response above means what you want is located at "/user" so the mobile app will need to make a request to
res.json(user)
//Response to Android app
{
name: "Arpit Yadav",
phone: 555-555
}
res.redirect sends status code 302 (if not specified), and location (route) to browser, after which browser redirects the request to the specified location, whereas res.json sets Content-Type: application/json and sends data to the browser.
Redirection is generally meant for browser only, but, you can use it for mobile. In that case, you have to handle the logic to re-request with updated location received from server that is not recommended.
In nutshell, both have different purpose. res.redirect to move clients to different route and res.json to actually sends the data.

Handling Mobile app backend API domain change - iOS & Android

We have a mobile app that calls endpoints on host https://www.currentdomain.com. we are migrating to https://www.newdomain.com in a month
The network team is planning to setup a dns redirect from currentdomain to newdomain.
What is the best possible way to handle this change in the app with minimal change and work? What will happen if the app calls the endpoint on currentdomain after setting up the dns redirect?
You can support redirection in your APIs.I am not sure how much is it possible at your end but if yes, then no changes will be required at app side.
Otherwise http redirection can be handled easily by apps, like in iOS 1 method needs to be added & can redirect request to the desired url.
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/RequestChanges.html
Redirect handler in android
https://developer.android.com/reference/org/apache/http/client/RedirectHandler.html

Relevance of User Agent in HTTP Requests

My friend implemented an HTTP POST request in iOS and it was working fine.
I have tried to implement the same in Android, but it doesn't work until I added the User Agent (I got it with the help of some sniffer tools).
But in iOS he is not specifying the User Agent.
So,
What is the relevance of User Agent in HTTP Request?
Why is it not consistent between iOS and Android?
iOS already specifies the User Agent by default. The user agent sent with NSURLConnection on iOS is
User-Agent: <app identifier>/<app version> CFNetwork/609.1.4 Darwin/12.4.0
where <app identifier> is your bundle ID (e.g. com.company.app) and <app version> is the current version of your app. Apparently, as you experience, Android does not set a default User Agent with (non-browser) HTTP requests.
The server can use this information to adapt its response to the client's needs; e.g. showing a mobile version of a webpage instead of a desktop version, or just don't return anything (to prevent simple screen scraping).

how to make a faked Android/ios http post request from desktop

Is there a way to make a faked http post request from desktop, but looks like from a real iOS/Android hardware(i.e. iPhone 5s 6.7 square inches, Samsung Galaxy 5.1-inch)?
I have no clue what’s the difference between the requests from deferent device(header,body...), how can a server know where the request from?
Thanks a lot. Merry Christmas.
The only difference is User-Agent.
You should easily be able to change it in your request, whatever the request is.
When your browser makes a request, among different headers there is a "User-Agent" header containing details of your browser and your OS. Take a look here and here.
I would use a REST Client like Postman for Chrome to send a POST Request along with the "User-Agent" string of my choice.
You can also use Chrome Developer Tools (opens with ctrl+shift+i in Windows) for the emulation feature that lets you emulate among a variety of devices. More info about that here.
With the emulation method in Chrome you can easily hit your server/webpage like you would normally by typing the URL in your browser (GET requests) from any of the available devices.

Why the user agent is sent as "Apache-HttpClient/UNAVAILABLE (java 1.4)”

A sample mobile application sends POST requests to a HTTP server which we use to process information sent from the mobile application. We parse HTTP headers and the User-Agent header is always seen as "Apache-HttpClient" on all Android devices with different OSes.
If i perform any action from app in android device, it returns the user agent as Apache-HttpClient/UNAVAILABLE (java 1.4)
what's the problem? It doesn't provide me a User Agent string which contains information like OS information and other details.. Has anyone seen similar behavior before?
Apache-HttpClient/UNAVAILABLE (java 1.4)
Is the default User Agent string for the Apache client that your app is using, it is not an error in itself.
This client know's very little about the system that it is running on, which is for the best - it's just a simple one-size-fits-all method for an Android device (which could be a phone, a tablet, a TV or even a car!) to make http requests to the outside world.
User Agent strings are a way for User Agents (read "browsers") to identify themselves.
In the case of an Android App, your App is the browser, so the User agent string is for you to define within your app.
See: Android Generic User Agent (UA)
If you want to send information about the device then you need to collect that information with your app and then send it. Though, if you are collecting that data then you might as well put it in the body of the request rather than HTTP headers anyway.

Categories

Resources