Follow-up to: How do I open a maxon::Url in the default web browser?
Hi,
I am trying to open a maxon::URL in the browser. It basically works, but lacks essential support for HTML anchors (delimited with "#") and - even more important - does not seem to handle query parameters (starting with "?" and separated with "&") correctly by default.
Here is some code about the latter. I want to open the website where potential customers can request an activation key for my plugin:
// Build request query string
maxon::BaseArray<maxon::String> urlQueryParts;
if (licensingInfo.firstName.IsPopulated())
{
urlQueryParts.Append("firstname="_s + licensingInfo.firstName) iferr_ignore();
}
if (licensingInfo.lastName.IsPopulated())
{
urlQueryParts.Append("lastname="_s + licensingInfo.lastName) iferr_ignore();
}
if (licensingInfo.organization.IsPopulated())
{
urlQueryParts.Append("organization="_s + licensingInfo.organization) iferr_ignore();
}
if (licensingInfo.systemCode.IsPopulated())
{
urlQueryParts.Append("inputcode="_s + licensingInfo.systemCode) iferr_ignore();
}
const maxon::String urlQueryString(JoinElements(urlQueryParts, "&"_s));
// Build request URL
maxon::Url url(GeLoadString(IDS_DEMOKEYGENERATORURL));
url.Set(maxon::URLFLAGS::QUERY, urlQueryString) iferr_ignore();
// DEBUG: Print URL to console
maxon::String urlString = url.ToString(nullptr);
GePrint(urlString);
// Open URL in browser
url.IoShowInOS(maxon::IOSHOWINOSFLAGS::OPEN_IN_EXPLORER) iferr_ignore();
The part with adding the query parameters to the URL works fine, even though I think it's quite a lot of code for something so simple. I'm doing it this way, because the SDK docs about UrlInterface::SetUrl()
kind of hints to this.
The GePrint(urlString)
call prints the following:
https://demo.mypluginsite.com?firstname=Arthur&lastname=Dent&inputcode=14004902462
So, that looks like exactly what I need. However, when calling url.IoShowInOS()
, Safari tries to open this URL:
https://demo.mypluginsite.com%3ffirstname=arthur&lastname=dent&inputcode=14004902462
And when I set my MacBook's default browser to Chrome instead, Chrome just opens a new tab at about:blank
. This happens on my old macBook with El Capitan as well as on a new iMac with macOS Catalina.
My questions:
- Why are the firstname and lastname values lower-case, and how can I prevent that from happening?
- Why is the "?" before the query parameters escaped, and how can I prevent that from happening?
- Why does Chrome not open the URL at all?
Thanks for help & advice!
Cheers,
Frank