Reputation: 21
I am accessing the Google Maps API via a TWebBrowser in Delphi XE3.
Initially the TWebBrowser is loaded via Navigate2 to 'about:blank'. The HTML to be rendered is then generated dynamically in code and loaded into the TWebBrowser via a stream.
This is all fine, as long as I use the free maps API. To use Maps for Business, the request for the API has to come from a pre-registered URL, which Google determines based on the referer header in the GET request that the "browser" usually sends when it loads the Javascript. Even though I specify a referer header in the initial Navigate2 call, when the generated HTML is loaded and rendered and the GET request for the API Javascript is sent by the TWebBrowser, the request does not contain a referer header, so the request is rejected. I confirmed that no referer header is sent using Fiddler.
It looks like the TWebBrowser only sends the referer header when actually navigating to a URL, not when sending a GET request, as when loading the API from a script element.
I can't use Navigate2 to load the "web page", since there is no server to load it from.
Is there any way to force TWebBrowser to include a specific referer header when it issues GETs, when the HTML it is rendering is loaded from a stream? After a couple of hours of searching, I have not found any hint of a way to do this.
Upvotes: 2
Views: 525
Reputation: 597951
Before you dynamically load HTML into TWebBrowser
, modify the HTML to insert a <base href="...">
tag into the HTML's <head>
to indicate the URL where the HTML originally came from. That URL is then used for resolving relative URLs, establish the Referer, etc.
Upvotes: 2