{"id":6053,"date":"2026-04-25T23:16:33","date_gmt":"2026-04-25T23:16:33","guid":{"rendered":"https:\/\/castle-engine.io\/wp\/?p=6053"},"modified":"2026-04-25T23:16:33","modified_gmt":"2026-04-25T23:16:33","slug":"web-target-getting-url-parameters-downloading-resources-using-tcastledownload","status":"publish","type":"post","link":"https:\/\/castle-engine.io\/wp\/2026\/04\/25\/web-target-getting-url-parameters-downloading-resources-using-tcastledownload\/","title":{"rendered":"Web target: getting URL parameters, downloading resources using TCastleDownload"},"content":{"rendered":"<table class=\"thumbnails thumbnails-align-right\"><tr><td>\n          <a href=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_2.png\"\n             class=\"screenshot\"\n             title=\"random_image_from_unsplash example on web\"><img loading=\"lazy\" decoding=\"async\"\n            style=\"float: right\"\n            src=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_2-200x94.png\"\n             width=\"200\" height=\"94\" \n            alt=\"random_image_from_unsplash example on web\"\n          ><\/a><\/td><\/tr><tr><td>\n          <a href=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_1.png\"\n             class=\"screenshot\"\n             title=\"asynchronous_download example on web\"><img loading=\"lazy\" decoding=\"async\"\n            style=\"float: right\"\n            src=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_1-200x95.png\"\n             width=\"200\" height=\"95\" \n            alt=\"asynchronous_download example on web\"\n          ><\/a><\/td><\/tr><tr><td>\n          <a href=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_3.png\"\n             class=\"screenshot\"\n             title=\"remote_logging example on web\"><img loading=\"lazy\" decoding=\"async\"\n            style=\"float: right\"\n            src=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_3-200x94.png\"\n             width=\"200\" height=\"94\" \n            alt=\"remote_logging example on web\"\n          ><\/a><\/td><\/tr><\/table>\n<p>We add 2 new features to our <a href=\"https:\/\/castle-engine.io\/web\">web target<\/a>:<\/p>\n<ol>\n<li>New methods to read URL through which your page was accessed, and get query parameters of this URL. The use-case is creating webpages that react to URL parameters, e.g. expose a model viewer on URL like <code>https:\/\/viewer.castle-engine.io\/?url=http:\/\/example.org\/model.gltf<\/code> (working version of this coming soon!). Use these methods:\n<ul>\n<li><code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleWindow.TCastleApplication.html#PageUrl\">Application.PageUrl<\/a><\/code> &#8211; get entire URL as a string,<\/p>\n<\/li>\n<li>\n<p><code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleWindow.TCastleApplication.html#PageUrlQuery\">Application.PageUrlQuery<\/a><\/code> &#8211; get query part of the URL (the part from <code>?<\/code>), as a string,<\/p>\n<\/li>\n<li>\n<p><code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleWindow.TCastleApplication.html#PageUrlParameter-String-\">Application.PageUrlParameter<\/a><\/code> &#8211; get value of a specific query parameter,<\/p>\n<\/li>\n<li>\n<p><code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleWindow.TCastleApplication.html#PageUrlParameters\">Application.PageUrlParameters<\/a><\/code> &#8211; get all query parameters as a dictionary<\/p>\n<\/li>\n<\/ul>\n<p>This API exists on all platforms, just returns nothing on non-web platforms. So you don&#8217;t need to use any <code>$ifdef WASI<\/code> when accessing this.<\/p>\n<\/li>\n<li>\n<p><code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleDownload.TCastleDownload.html\">TCastleDownload<\/a><\/code> class works on the <em>web<\/em> now. It allows to make HTTP requests, e.g. download files or communicate with REST APIs. See <a href=\"https:\/\/castle-engine.io\/url\">URLs, loading resources<\/a> and <a href=\"https:\/\/castle-engine.io\/multi_player\">Multi-player (network communication)<\/a> for general usage description.<\/p>\n<p>Underneath, it uses <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/XMLHttpRequest\">XMLHttpRequest<\/a> which is the standard way to make HTTP requests on the web. It supports all HTTP methods, custom headers, progress monitoring and generally all features of our <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleDownload.TCastleDownload.html\">TCastleDownload<\/a><\/code>.<\/p>\n<p>Examples:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/examples\/network\/asynchronous_download\">examples\/network\/asynchronous_download\/<\/a> &#8211; simply download real data from various real servers. Downloads asynchronously (without blocking the UI, animations etc.) I added to this example showing (in log) MD5 and SHA-256 checksums of the downloaded contents, so we can easily confirm that indeed it downloads 100% correct data.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/examples\/network\/random_image_from_unsplash\">examples\/network\/random_image_from_unsplash\/<\/a> &#8211; communicate using REST with Unsplash API. Shows that, beyond simple downloading, also <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleDownload.TCastleDownload.html#HttpHeader-String-String-\">TCastleDownload.HttpHeader<\/a><\/code> works.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/examples\/network\/remote_logging\">examples\/network\/remote_logging\/<\/a> &#8211; send using POST (<code>Request.HttpMethod := hmPost<\/code>, <code>Request.HttpPostData.Values[ParameterKey] := ParameterValue<\/code>). I verified on the server (that receives data using <a href=\"https:\/\/github.com\/castle-engine\/cge-www\/blob\/master\/htdocs\/cge_logger.php\">simplest PHP script that logs POST parameter<\/a>) that it received correct data.<\/p>\n<\/li>\n<\/ul>\n<p>Note that <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CORS\">CORS (Cross-Origin Resource Sharing)<\/a> security will prevent our application on the web from downloading things from other domains.<\/p>\n<p>This is a standard security feature of web browsers. It is unavoidable from our side (application living inside a web page). All web application (using JS or WebAssembly) have to deal with it.<\/p>\n<ul>\n<li>\n<p>For development, you can disable CORS in your browser. E.g. on <em>Firefox<\/em> with <a href=\"https:\/\/addons.mozilla.org\/pl\/firefox\/addon\/cors-everywhere\/\">CORS Everywhere extension does the job<\/a>. <em>Chrome<\/em> supports <code>--disable-web-security<\/code> command-line option. Search the web for details specific to your browser.<\/p>\n<\/li>\n<li>\n<p>For real usage, the server has to be configured to allow downloading from it. It generally involves configuring the server to return appropriate header, like <code>Access-Control-Allow-Origin: *<\/code>.  See <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CORS\">CORS documentation at MDN<\/a> and <a href=\"https:\/\/enable-cors.org\/server_apache.html\">example configuration for Apache<\/a>.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>We add 2 new features to our web target: New methods to read URL through which your page was accessed, and get query parameters of this URL. The use-case is creating webpages that react to URL parameters, e.g. expose a model viewer on URL like https:\/\/viewer.castle-engine.io\/?url=http:\/\/example.org\/model.gltf (working version of this coming soon!). Use these methods: &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/castle-engine.io\/wp\/2026\/04\/25\/web-target-getting-url-parameters-downloading-resources-using-tcastledownload\/\" class=\"more-link\">Continue reading  \u27a4<span class=\"screen-reader-text\"> &#8220;Web target: getting URL parameters, downloading resources using TCastleDownload&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":6058,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"publish_to_discourse":"1","publish_post_category":"9","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"7639","discourse_permalink":"https:\/\/forum.castle-engine.io\/t\/web-target-getting-url-parameters-downloading-resources-using-tcastledownload\/2144","wpdc_publishing_response":"","wpdc_publishing_error":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-6053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2026\/04\/web_castle_download_2.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9IgYW-1zD","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/6053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/comments?post=6053"}],"version-history":[{"count":5,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/6053\/revisions"}],"predecessor-version":[{"id":6061,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/6053\/revisions\/6061"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media\/6058"}],"wp:attachment":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media?parent=6053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/categories?post=6053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/tags?post=6053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}