In some cases we need to modify the request. For example we may need to add a header to the message before it is sent.
B4X:
Dim Job As HttpJob
Job.Initialize("Job", Me)
Job.Download("http://www.b4x.com")
' ****** The header is set after Download is called ?!
Job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)")
Note that it is not possible to call Job.GetRequest before Job.Download as the request is initialized in Job.Download.
Surely that depends on the status of HTTPutils2 service? My guess is that it will not work if the service is active but it could stand a chance of working if the service has to be started.
It works because CallSubDelayed2 is used to start the service and call a sub. Since CallSubDelayed uses the message queue, the service code/sub will not be executed until the current thread exits, which will exit after SetHeader is set, and whenever the calling sub completes.
EDIT: Ofcourse, I didnt know this before to ever use it. Good technique, but not so straight forward for readability.