Multiple POST requests using HTTPUtils

COBRASoft

Active Member
Licensed User
Longtime User
Hi,

I’m using HTTPUtils with POST to communicate with webservices. This works fine as long as I POST 1 at a time, wait for the response and the post the next one.

Is there a way to use POST with multiple requests at the 'same' time?

Here is an example of what I try to do now, but only the first request is dealt with.

B4X:
    '--- Countries
    btnCachCountry.SetBackgroundImage(Design.bmpRefresh)
    Dim objMap As Map: objMap.Initialize: Shared.AddLoginLanguage(objMap)
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
    HttpUtils.PostString("CountryList", Shared.CountryListURL, objJSon.ToString, Shared.ContentType)

    '--- VehicleBrands
    btnCachVehicleBrand.SetBackgroundImage(Design.bmpRefresh)
    Dim objMap As Map: objMap.Initialize: Shared.AddLogin(objMap)
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
    HttpUtils.PostString("VehicleBrandList", Shared.VehicleBrandListURL, objJSon.ToString, Shared.ContentType)
    '--- VehicleBrandModels
    btnCachVehicleBrandModel.SetBackgroundImage(Design.bmpRefresh)
    Dim objMap As Map: objMap.Initialize: Shared.AddLogin(objMap)
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap): objMap.Put("CRBR_ID", Shared.EmptyGuid)
    HttpUtils.PostString("VehicleBrandModelList", Shared.VehicleBrandModelListURL, objJSon.ToString, Shared.ContentType)
    '--- VehicleColors
    btnCachVehicleColor.SetBackgroundImage(Design.bmpRefresh)
    Dim objMap As Map: objMap.Initialize: Shared.AddLoginLanguage(objMap)
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
    HttpUtils.PostString("VehicleColorList", Shared.VehicleColorListURL, objJSon.ToString, Shared.ContentType)
    '--- VehicleTypes
    btnCachVehicleType.SetBackgroundImage(Design.bmpRefresh)
    Dim objMap As Map: objMap.Initialize: Shared.AddLoginLanguage(objMap)
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
    HttpUtils.PostString("VehicleTypeList", Shared.VehicleTypeListURL, objJSon.ToString, Shared.ContentType)

Greetings,
Sigurd
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can not submit a new job while an existing job runs.

Currently HttpUtils supports jobs with multiple GET requests or jobs with a single POST request.

If you must send multiple POST requests then you have three options:
- Modify HttpUtils / HttpUtilsService and change the GET requests handling to send POST requests.
- Store the POST requests in a List and send them one after another (when the previous one finishes).
- Don't use HttpUtils. Use HttpClient directly.
 
Upvote 0
Top