'How to download a file from a URL which is passed as a query string?

I am passing a URL which has another URL in the query string. I have shown an example below: https://www.aaa.com/triBECKML/kmlHelper.htm?https://lkshd.ty.etys.nux/incoming/triBEC/final_year_base_data/KMLS/NetAverages.kml

I have tried a WebClient to download the file but it only downloads an empty .kml. Additionally when I call the method with just the 2nd URL (IN THE QUERY STRING), the file gets downloaded smoothly.

using (var client = new WebClient())
            {
                client.DownloadFile(url, destinationPath);
            }


Solution 1:[1]

You can try to split the string. And use only the second part?

Example:

string[] urls = url.Split('?');
using (var client = new WebClient())
{
    client.DownloadFile(urls[1], destinationPath); 
}

This splits the url string and puts the first url and the second in a array. Then you can use the url you want.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zoe stands with Ukraine