Thanks in advance for your answers. The situation is the following:
-
I must process N times some records stored locally in sqlite
-
To process each record I must make a first network.request to a web service 01 and once this first request is finished , I must make a second network.request to a web service 02
-
I have tried to condense the code in this (N=3):
– TEST WS local json = require (“json”) print (os.date()…" -------------- TEST WS START --------------------") local function wsTest02Call( event ) if ( event.isError ) then print( “Network error: “, event.response ) else print ( os.date()…” RESPONSE: " … event.response ) end end local function wsTest01Call( event ) if ( event.isError ) then print( “Network error: “, event.response ) else print ( os.date()…” RESPONSE: " … event.response ) local response = json.decode( event.response ) if (response.Status ==“ok”) then local headers = {} headers[“Content-Type”] = “application/x-www-form-urlencoded” headers[“Accept-Language”] = “en-US” headers[“User-Agent”] = “My Corona APP” local body = “qty=50&priceunit=100” local params = {} params.headers = headers params.body = body params.timeout = 15 – Call WS02 network.request( “https://aws05.phonemas.com/ws/wstest02.php”, “POST”, wsTest02Call, params ) end end end local function callWS( ) local headers = {} headers[“Content-Type”] = “application/x-www-form-urlencoded” headers[“Accept-Language”] = “en-US” headers[“User-Agent”] = “My Corona APP” local body = “color=red&size=small” local params = {} params.headers = headers params.body = body params.timeout = 15 – CAL WS01 network.request( “https://aws05.phonemas.com/ws/wstest01.php”, “POST”, wsTest01Call, params ) end – LOOP 3 TIMES for i=1,3 do callWS() end print (os.date()…” -------------- TEST WS END --------------------”)
The result is as follows:
Copyright © 2009-2018 C o r o n a L a b s I n c .
Version: 3.0.0
Build: 2018.3228
Loading project from: ~/Documents/Corona Projects/Samples/Test WS
Project sandbox folder: ~/Library/Application Support/Corona Simulator/Test WS-81A8676CBB0C22A036E551B82F6EBB38
Platform: GT-I9300 / x86_64 / 10.12.6 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-10.25.19 / 2018.3228 / en-CO | CO | en_CO | en
Mon Mar 12 08:16:08 2018 -------------- TEST WS START --------------------
Mon Mar 12 08:16:08 2018 -------------- TEST WS END --------------------
Mon Mar 12 08:16:11 2018 RESPONSE: {“Status”:“ok”,“info”:“MSG: Thank you. Processed requirement 01)”}
Mon Mar 12 08:16:11 2018 RESPONSE: {“Status”:“ok”,“info”:“MSG: Thank you. Processed requirement 01)”}
Mon Mar 12 08:16:11 2018 RESPONSE: {“Status”:“ok”,“info”:“MSG: Thank you. Processed requirement 01)”}
Mon Mar 12 08:16:15 2018 RESPONSE: {“Status”:“ok”,“info”:“MSG: Thank you. Processed requirement 02)”}
Mon Mar 12 08:16:15 2018 RESPONSE: {“Status”:“ok”,“info”:“MSG: Thank you. Processed requirement 02)”}
Mon Mar 12 08:16:15 2018 RESPONSE: {“Status”:“ok”,“info”:“MSG: Thank you. Processed requirement 02)”}
It is observed that they are not being executed as I need it (point 2).
The question is: How should I adjust my code to run in cascade (one behind the other)?
The URLs in the code are real and public, for those who wish to review.
Regards,
Solón


