L lancaster Member Licensed User Longtime User Dec 20, 2018 #1 I need to trap both HTTP POST 'success' and 'error' conditions within a single sub... I'm currently using OkHttp to POST API calls to a service and I have 2 Wait For statements as follows: Wait For postRequest_ResponseError ( ....) (some code) Wait For postRequest_ResponseSuccess ( ...) (some code) As these events are mutually exclusive it appears I only resume after the first one. If the job is successful, control is never returned to my sub. Is is possible to wait for one of two mutually exclusive events like this? Thanks for any help.
I need to trap both HTTP POST 'success' and 'error' conditions within a single sub... I'm currently using OkHttp to POST API calls to a service and I have 2 Wait For statements as follows: Wait For postRequest_ResponseError ( ....) (some code) Wait For postRequest_ResponseSuccess ( ...) (some code) As these events are mutually exclusive it appears I only resume after the first one. If the job is successful, control is never returned to my sub. Is is possible to wait for one of two mutually exclusive events like this? Thanks for any help.
DonManfred Expert Licensed User Longtime User Dec 20, 2018 #2 Sounds like an mistake to use the httpclient directly. Use okhttputils2 and check the job result. If it return successful or not can be checked with one wait for. https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/ Upvote 0
Sounds like an mistake to use the httpclient directly. Use okhttputils2 and check the job result. If it return successful or not can be checked with one wait for. https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/
L lancaster Member Licensed User Longtime User Dec 20, 2018 #3 Hi Manfred, Thanks. I did look at using the okHttpUtils library but I need to use okHttpClient.InitializeAcceptAll to handle HTTPS certificate issues and that doesn't exist in the replacement libraries. Hence that why I'm still using OkHttpClient. Dave Lancaster Upvote 0
Hi Manfred, Thanks. I did look at using the okHttpUtils library but I need to use okHttpClient.InitializeAcceptAll to handle HTTPS certificate issues and that doesn't exist in the replacement libraries. Hence that why I'm still using OkHttpClient. Dave Lancaster
DonManfred Expert Licensed User Longtime User Dec 20, 2018 #4 download the okhttputils source modules, change hc.initialize to hc.initializeall and use the sourcemodules instead of the library when you work with okhttputils. Upvote 0
download the okhttputils source modules, change hc.initialize to hc.initializeall and use the sourcemodules instead of the library when you work with okhttputils.
Erel B4X founder Staff member Licensed User Longtime User Dec 21, 2018 #5 DonManfred said: download the okhttputils source modules, change hc.initialize to hc.initializeall and use the sourcemodules instead of the library when you work with okhttputils. Click to expand... This is the correct solution. No reason to use OkHttpClient directly. Upvote 0
DonManfred said: download the okhttputils source modules, change hc.initialize to hc.initializeall and use the sourcemodules instead of the library when you work with okhttputils. Click to expand... This is the correct solution. No reason to use OkHttpClient directly.
L lancaster Member Licensed User Longtime User Dec 21, 2018 #6 and it's an excellent solution thanks. Has simplified the code significantly and once you also deal with headers and cookies 'after' the HttpJob.PostString call (which seemed a little illogical until it worked) ... Thanks. Upvote 0
and it's an excellent solution thanks. Has simplified the code significantly and once you also deal with headers and cookies 'after' the HttpJob.PostString call (which seemed a little illogical until it worked) ... Thanks.