Handling axios client network disconnect errors and retrying requests in React Native - post

We're creating a mobile application in react native. Right now we're facing a problem, a client may send a request and disconnect after that. The request on a BE is finished, but when a user opens the app, pops ups a network error and the user does not actually know the status of the request.
Theoretically, in some cases like GET, and UPDATE we can just send the request again, but how to handle a POST request, when a new entity is being created in a DB on BE? Or when BE is connected to a few other BE and while sending the request, BE A can send the request to BE B, but the client disconnects and does not know the status of the request?
How is this kind of problem is usually solved in mobile apps? While using the mobile app someone may call and the network will be disconnected.
Thank you for your responses.
We tried to repeat requests on client disconnect, but we're not sure how to repeat POST requests when a new entity is added to the DB.

Related

timeout in telegram.bot webhook - asp.net mvc

I had been developed a telegram bot using Telegram.Bot.
I tried to rework with the bot, First I created bot using BotFather and got token.
I set webhook server api address in telegram api. But when I check webhookinfo it returns this error
https://api.telegram.org/botToken/getWebhookinfo
respone:
"last_error_date":1585419712,"last_error_message":"Connection timed out"
I checked it need TLS12 to have secure connection using
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
But It's not getting updates in my server and show time out error.
I tried posting using postman and ngrok to run on my iisexpress and I'm getting data and can sending messages to bot in my localhost.
But In hosting it's not working, whats wrong with new Telegram.Bot library or telegram server?
update
I checked with postman my hosting url, post man also cant connect to that url. what can be wrong with my codes?
This is response when i'm call update receiving URL in my hosting:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.10.34.35:443
I got problem, the certificate which we use should be valid one, not free.
For more information please study this link:
https://core.telegram.org/bots/webhooks

Limit the server to only respond to HTTP requests made from an iOS app - without username and password

I have an iOS app where the user can makes HTTP requests from their phones and the HTTP returns information based on the zip code that the user provides through the phone.
My issue is that anyone can type the URL and the server would respond with the information that corresponds to the zip code they input e.g. http://example.com/zip-code/78515.
My questions is, can I limit the server to only respond to requests made from my iOS app without the user having to create a user and password? In other words, if someone types http://example.com/zip-code/78515 directly in a browser I want the server to ignore the request but if the request comes from my iOS app I want the server to respond accordingly.
For the HTTP request I'm using Laravel.
Here is my Laravel code.
Route:
Route::get('zip-code/{zipCode}', 'AppsAPIController#information');
Controller:
class AppsAPIController extends Controller
{
public function information($zipCode)
{
$info = CityInfo::where('ZipCode', $zipCode)->get();
return ($info);
}
}
Request:
http://example.com/zip-code/78515
Again, the question is, how can I limit the server to only respond to requests made from my iOS app without the user having to create a username and password?
This package seems to do that
https://github.com/spinen/laravel-browser-filter
Basically, you are adding a middleware that reads the user agent out of the request, and denies the rest.
There is no foolproof way to respond only to requests made by your app.
User agent sniffing, navigator feature detection, and like measures may deter most basic attempts to load information from that url (like search engine bots), but anyone with a little time can learn to replicate the HTTP requests made by your app, defeating those measures.
Even requiring a login will not prevent external request (they can send requests matching your login workflow to obtain a valid token, then request the restricted url with it).
(via the comments) I just don’t want to overload the server with unnecessary requests.
In that case, there's a much better solution. Laravel ships with a throttle middleware, which you can use to limit the number of requests per minute per IP (or per logged-in user, if they're authenticated).
Just add throttle:60,1 to your route's middleware and it'll max out at 60 requests per minute for a particular IP address. Set it to something relatively high (so normal use doesn't hit it), but it'll prevent millions of requests from the same IP from using up too many resources.

Phonegap iOS ajax request never completes

I have a phonegap app which connects to a web service and authenticates using http basic authentication. It is built using phonegap build and targets Android and iOS.
On a login view, an ajax request fires against the remote server to check if credentials are correct, then if so, logs the user in to the main application.
This completes successfully in ripple emulator on desktop pc and when also when deployed onto an Android device.
However, when the app is deployed onto an iOS device (ipod touch) the authentication request simply does not ever complete. Using phonegap remote debugger I can see that the ajax request starts but never completes. It is always in a pending state. I use jquery ajax success, error and complete handlers for the request, but none of them are ever hit so I don't get the chance to see any error messages returned from the server. The request never seems to complete.
I have tried making ajax requests to other remote web sites to test that my app can communicate and they succeed, so it doesn't seem as though I have white-listing issues.
Any ideas of what the issue could be?
Please read the update to this answer at bottom.
Original answer
I have found what the issue is and managed to get basic authentication working.
The issue was that the web server was expecting basic authentication details to be preemptively sent with the request.
To do this use the 'headers' property of jquery ajax as shown below:
$.ajax
({
type: "GET",
url: "https://webserver/authenticate",
headers: {
"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
}
})
.done(function(){
alert('Authenticated!')
})
.fail(function(){
alert('Error!')
});
See related answer:
https://stackoverflow.com/a/11960692/1463497
Update
I found in the end that there is no reliable way of using basic authentication in a web view in iOS. I.e everything is fine if correct credentials are entered but when they are not and the 401 challenge response comes along, iOS web view can't seem to handle it.
In the end, the web service authentication was implemented by simply passing 'username' and 'password' parameters as part of the url:
url: "https://webserver/authenticate?username=abc&password=123"
This is the only consistent way I found of getting authentication to work across iOS and Android in a web view (by getting rid of basic authentication altogether). This of course meant updating the web service itself to accept authentication in this way.

How to ensure that only my app connects to the server?

I'm going to write an iOS app that interacts with php server. I wanna be sure that only my app but nobody else (how is able to intercept and read my requests) can connect to the server. I mean if somebody else sends a request, this request must be denied by the server. How do i do that?

Facebook Real-time Updates is not posting data

I have set up the real time subscription for facebook, the subscription is done successfully but I am only getting friends updates if friends are added or removed, apart from this I am not getting anything for like "books, checkins, work, education etc...". Facebook is sending the Token to my web server. That is good so far. My server sends back the response to facebook. So far Configuration is done successfully.
Another Issue is - I am not able to see the incomming request in Fiddler. I have tried below to check the incomming request...
if (oSession.host.toLowerCase() == "IP Address:8888")
oSession.host = "IP Address:Port Number";
Sometimes (especially with IE) Fiddler has to be started before you start your debugging session.

Resources