Erel B4X founder Staff member Licensed User Longtime User Nov 15, 2012 #1 This question is about HttpUtils2: HttpUtils2 - Web services are now even simpler 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. Code: Copy 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. Does it work? Why?
This question is about HttpUtils2: HttpUtils2 - Web services are now even simpler 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. Code: Copy 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. Does it work? Why?
K keirS Well-Known Member Licensed User Longtime User Nov 15, 2012 #2 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. Upvote 0
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.
thedesolatesoul Expert Licensed User Longtime User Nov 15, 2012 #3 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. Upvote 0
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.
Erel B4X founder Staff member Licensed User Longtime User Nov 15, 2012 #4 :sign0098: You are correct. This is a side effect of CallSubDelayed. CallSubDelayed is used here to call the service from the class. That was quick. Next time I will think of a more challenging question... Upvote 0
:sign0098: You are correct. This is a side effect of CallSubDelayed. CallSubDelayed is used here to call the service from the class. That was quick. Next time I will think of a more challenging question...
thedesolatesoul Expert Licensed User Longtime User Nov 15, 2012 #5 Erel said: :sign0098: You are correct. This is a side effect of CallSubDelayed. CallSubDelayed is used here to call the service from the class. That was quick. Next time I will think of a more challenging question... Click to expand... This will be fun :icon_clap: Upvote 0
Erel said: :sign0098: You are correct. This is a side effect of CallSubDelayed. CallSubDelayed is used here to call the service from the class. That was quick. Next time I will think of a more challenging question... Click to expand... This will be fun :icon_clap: