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.
Related
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
I have a rails project whose API's are used by two different but related apps.
One app (Parent) is made using Unity, while other one (Child) is with native (iOS & Android).
In case of error response.
Unity app requires 2xx series status code,in case of any other status code they read it as success case.
While native (iOS & Android) apps need 4xx series status code, in case of any other status code they read it as success case.
Is there any way that from request I can know that which app sent request?
or any other solution to handle this?
Is there any way that from request I can know that which app sent
request?
Yes. Several ways.
1.Use form to send which device is making the request then access this fro your rail server.
WWWForm form = new WWWForm();
//From Unity
form.AddField("App", "Unity");
Or
//From Native
form.AddField("App", "Native");
Then send:
UnityWebRequest uwr = UnityWebRequest.Post(url, form);
yield return uwr.SendWebRequest();
2.Use a custom header to send which device is making the request then access this from your rail server.
//From Unity
UnityWebRequest.SetRequestHeader("App", "Unity");
Or
//From Native
UnityWebRequest.SetRequestHeader("App", "Native");
All you need to do is access "App" on rail for both of these.
3.Use json or xml to store which device the request is coming from the access this from the server.
The API used here is for Unity but you can do similar thing on iOS and Android too for the native app with Object-C and Java API. It's still the-same thing.
request method has parameter as
request.user_agent
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.
I need to develop an API for web as well as mobile with NodeJS as backend. Since, both have common endpoints --> I was wondering how to handle error cases like for e.g. --> if there is an error and user is on web I can do res.redirect and the user will be redirected whereas if the request was from mobile then I will have to set an 'action' variable which will guide the mobile app to take the next action for e.g. ask the user to login again.
app.get('/users/musicList', function(req, res){
// check with db.
// lets say there is some error --> the API token is not valid so user needs to
// login
if (req was from web) {
res.redirect('/signin');
} else {
var result = {action : 'SIGNIN'};
res.status(200).json(result);
}
});
Is this the correct way to go ? It makes code look a bit messy. Any suggestions.
An Easy way to do this is to have two different endpoints for mobile and web. (Wait I have two more solution).But this would result in code duplication.
web: domain/route
mobile: domain/api/route
Another way is to have only api/route which uses only json. And to handle the error and routing in front end. This works if you are using front-end frameworks like angular and using AJAX requests.
Third one is to check for the client need and acting as in your question. Check this link for how to determine what client needs.
NodeJS : Validating request type (checking for JSON or HTML)
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