Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent duplicate http requests?

We have Intermec CK71 mobile devices (WiFi). There will always be a scenario in which the device sends a request (GET, PUT, or POST), then loses connection. What methods can we use to prevent duplicate PUTs or POSTs? How does the client device know whether or not the server processed its request before losing the connection?

I have seen similar posts like this but the marked answer doesn't go into much detail. I'm not even sure where to begin. Should I be looking into caching (ETag, last modified), or some type of handshaking?

The client device has the .Net Compact Framework 3.5 on it and is hitting the server via its Web API 2 endpoints.

If someone can point me to the right direction or offer any suggestions it would be much appreciated. Thanks.

like image 417
BBauer42 Avatar asked Jan 26 '16 17:01

BBauer42


1 Answers

I am not using REST but as far as I read the information there is no easy way to get an acknowledge and avoid duplicate POST.

As with other high level API frameworks you are tied to what the API offers and it looks like the designers did not think about connection aborts.

The easiest way to workaround this seems to use an unique ID with every post and check the server for knowing these UID before re-posting. If the server does not response with OK for an POST, you have to assume the connection has broken or other things went wrong. Then query the server for the UID you posted to know if the pervious POST was succesful before you try another POST with the same data and UID.

Possibly there is some transaction encapsulation available with REST as available for sql server. A 'transaction' protocol would ensure that a POST has been processed succesfully or will be 'rolled' back, if something failed.

Sorry, but I do not know much about REST.

like image 77
josef Avatar answered Oct 18 '22 08:10

josef