Description: The following code allows you to set the request headers before the request is sent. This is useful for example with sites that block requests without a User-Agent header.
This code depends on HttpUtils2 and Http libraries:
It is a bit confusing as it seems that the header is set after the request was sent. However internally HttpJob uses CallSubDelayed to send the request. So the request will only be sent after the current code execution completes.
Note that you can set any number of headers.
The content type header should be set with SetContentType.
Tags: http headers, httputils2, user agent
This code depends on HttpUtils2 and Http libraries:
B4X:
Dim j As HttpJob
j.Initialize("job name", Me)
j.Download(<link>) 'it can also be PostString or any of the other methods
j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
It is a bit confusing as it seems that the header is set after the request was sent. However internally HttpJob uses CallSubDelayed to send the request. So the request will only be sent after the current code execution completes.
Note that you can set any number of headers.
The content type header should be set with SetContentType.
Tags: http headers, httputils2, user agent
Last edited: