B4J Question Using Wait For for 2 different events

Discussion in 'B4J Questions' started by lancaster, Dec 20, 2018.

  1. lancaster

    lancaster Member Licensed User

    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.
  2. DonManfred

    DonManfred Expert Licensed User

  3. lancaster

    lancaster Member Licensed User

    Hi Manfred,


    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
  4. DonManfred

    DonManfred Expert Licensed User

    download the okhttputils source modules, change hc.initialize to hc.initializeall and use the sourcemodules instead of the library when you work with okhttputils.
    MarkusR, inakigarm, Erel and 2 others like this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    This is the correct solution. No reason to use OkHttpClient directly.
  6. lancaster

    lancaster Member Licensed User

    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) ... ;)

    MarkusR likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice