HTTP Request from Web to Android - android

How can I make an HTTP request from a web application (like node js) to an android app?
The goal is to read if the response is a success, for example, from Web to Web I make an HTTP request to the IP/URL and, if it returns 200, I have success. It would work as a "ping" to check if the android app is "alive".
Note: I don't know apps architecture
Thanks!

Using web sockets ( example here: https://www.html5rocks.com/en/tutorials/websockets/basics/ ) will help u to achieve it

Related

How to intercept all http responses in flutter?

Is there any possible way to intercept all the network responses ? For example with electron js, I can do something like,
protocol.interceptBufferProtocol("http", (request, result) => {
if (request.url === "http://www.example.com/encryptedkey")
const decypted = decrypt(result)
return result(decrypted)
});
Once I add the above code, no matter who ( webview / a 3rd party library , or any thing in the electron app ) sends the requests to the http://www.example.com/encryptedkey the response receive to the client code is not the same response sent from the server. It is manipulated by above electron code. Is there any possible way to achieve this with a flutter app ? I searched on Google and found this library
But this won't work as I don't have control with some of the http request as they sends by 3rd party widget I use in the app.
Therefore I'm looking for a way to create some kind of proxy in between the server and flutter app.
Is this possible with flutter ? Any help regarding this really appreciate.

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.

How to identify web request client?

I have a web api and 2 another apps 1 is in xamarin and another is in angularjs.
I am calling api in xamarin Using HttpClient.
I am calling api in angularjs using $http service .
Now I want to implement different logic for HttpClient call and $http call, how can I recognize the web request client?
You can use the different User-Agent or custom HTTP header when making the web request.
You can find more details here: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields

Android cannot communicate with localdjango server?

I am trying to post data from my client android application to a django server.
for example I have User {login:---, email:---} and I wanna post them my LOCAL SERVER based on django.. what I should do ? any link or tutorial can be greatful, i can't find any thing really helpful.Thks
You need to make a HTTP request to your django server. Here is a similar question how to do a post request in android

How to make a post request to a meteor server from android application

I am making an android application in which I want to post some data to a web server for a chat service. I am thinking of using meteor which is based on node.js for the back end as well front end. How do I make a post request to node server in a meteor application from my android device?
Are you sure this is really what you want to do for a chat application?
Don't forget Meteor handles bi-directional communications between the client and server for you.
It's much more likely that you want to simply add the chat text to the database with a Collection insert call, with a Meteor Method call, or look also at Arunoda's meteor-streams smart package.
All 3 options will work faster and be easier to code, than relying on POST requests (don't forget, by default Meteor leverages an open WebSocket connection, when available).
You didn't mentioned if you are doing native android or using cordova for android. If you are using cordova the you can make http calls by Meteor's http API. See docs.
Sample POST request using meteor, you have to import http package as meteor add http:
Meteor.http.call("POST",
"http://your.serverurl.com/path",
{data: {some: "json", stuff: 1}},
function (error, result) {
if (result.statusCode === 200) {
//do something
}
});
Or if you are doing native android app. you can do this by Java HttpPost class. See this example

Categories

Resources