Mar 30, 2014 Replies: 12 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: Code: Copy 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: Sep 17, 2018 Click to expand...
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: Code: Copy 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
Peter Simpson Expert Licensed User Longtime User Apr 1, 2014 #4 That's great to know @Erel. So I'm presuming that the following line will work a treat then... Code: Copy AutoUpdateIP.GetRequest.Timeout = DateTime.TicksPerSecond * 45 AutoUpdateIP.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.92 Safari/537.36")
That's great to know @Erel. So I'm presuming that the following line will work a treat then... Code: Copy AutoUpdateIP.GetRequest.Timeout = DateTime.TicksPerSecond * 45 AutoUpdateIP.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.92 Safari/537.36")
Erel B4X founder Staff member Licensed User Longtime User Apr 2, 2014 #5 Yes. As long you first call the "download" method.
Nerdworld Member Licensed User Longtime User Jul 6, 2014 #6 I'm currently trying to set some headers this way, but i'm getting this error: Request.GetRequest().SetHeader("User-Agent", "SomeTesting") Unkown type: anywheresoftware.b4a.http.HttpClientWrapper.HttpUriRequestWrapper Are you missing a library reference? Is this coming from a version difference, or am i missing something?
I'm currently trying to set some headers this way, but i'm getting this error: Request.GetRequest().SetHeader("User-Agent", "SomeTesting") Unkown type: anywheresoftware.b4a.http.HttpClientWrapper.HttpUriRequestWrapper Are you missing a library reference? Is this coming from a version difference, or am i missing something?
Erel B4X founder Staff member Licensed User Longtime User Jul 6, 2014 #7 You need to add a reference to Http library.
D deantangNYP Active Member Licensed User Longtime User May 23, 2016 #9 May i know how to add into the Header the following - Basic authorisation - Username, password (base64 encoded) THANKS !!
May i know how to add into the Header the following - Basic authorisation - Username, password (base64 encoded) THANKS !!
Erel B4X founder Staff member Licensed User Longtime User May 23, 2016 #10 You can set Job.Username and Job.Password properties.
S seanfogg Member Licensed User Longtime User Mar 21, 2017 #11 Does this work with the PostString method also?
Erel B4X founder Staff member Licensed User Longtime User Mar 22, 2017 #13 That's true. It works with all methods.