0

I always use Application.FollowHyperlink on VBA to launch the default web browser such as Microsoft Edge under Windows 10. I shall avoid Shell.Application or dll ShellExecute().

But now some usually accessed web site has added User-Agent control. If it's not set, the web server refuses my request with a

HTTP/1.1 403 Forbidden

response.

According to Microsoft,

Application.FollowHyperlink Address, SubAddress, NewWindow, AddHistory, ExtraInfo, Method, _
  HeaderInfo

But I cannot send HeaderInfo, as I tried this:

Application.FollowHyperlink "https://www.example.com", "", false, false, "", 0, _
  "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"

without any success.

VBA error messageBox popups

enter image description here

In English: Running error '8': cannot download requested data (Cannot Download the information you requested).


To prove the header problem, curl also failed without User-Agent header (error HTTP/1.1 403 Forbidden):

curl -I https://www.example.com

enter image description here

But it worked under Powershell console like this:

curl -I -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" https://www.example.com

enter image description here

What's the good syntax for HeaderInfo on VBA to send http User-Agent header to web server, any idea ?

jacouh
  • 8,473
  • 5
  • 32
  • 43
  • Did you try adding as part of querystring? Also, could you make it looks like hyperlinks but actually have event code/controls tied to following method, which may be more reliable according to the authors: https://stackoverflow.com/questions/40462176/how-to-open-a-url-from-ms-access-with-parameters Failing that, depending on requirements, use xhr? Don't know how user is interacting with the link. – QHarr Sep 04 '21 at 20:17
  • Thank you @QHarr for your attention. Tried Application.FollowHyperlink "https://www.example.com?User-Agent=Chrome", "", false, false, "", 0, "" without access, but curl -I -H "User-Agent: Chrome" OK. – jacouh Sep 05 '21 at 11:08

0 Answers0