1

I'm trying to access a public file using a URL from Australian Bureau Of Statistics.

https://stat.data.abs.gov.au/sdmx-json/data/ABS_BLDG_APPROVALS_LGA2020/1.1.1.110.LGA2020.20660+20740+20830+20910+21110+21180+21450+21610+21890+22170+22310+22490+22670+22750+23110+23270+23430+23670+24130+24210+24330+24410+24600+24650+24850+24970+25060+25150+25250+25340+25710+25900+26080+26170+26350+26490+26980+27070+27260+27350+27450.M/all?detail=Full&dimensionAtObservation=AllDimensions&startPeriod=2020-07&endPeriod=2020-09

And can do so without an error using Firefox but when I try using powershell I get

"Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (403) Forbidden."

The code I'm using:

(New-Object System.Net.WebClient).DownloadFile('https://stat.data.abs.gov.au/sdmx-json/data/ABS_BLDG_APPROVALS_LGA2020/1.1.1.110.LGA2020.20660+20740+20830+20910+21110+21180+21450+21610+21890+22170+22310+22490+22670+22750+23110+23270+23430+23670+24130+24210+24330+24410+24600+24650+24850+24970+25060+25150+25250+25340+25710+25900+26080+26170+26350+26490+26980+27070+27260+27350+27450.M/all?detail=Full&dimensionAtObservation=AllDimensions&startPeriod=2020-07&endPeriod=2021-09','C:\temp\test')

powershell version 5.1

Edit: I should have mentioned that I have successfully run the powershell script on other websites, without error

sams
  • 439
  • 1
  • 4
  • 17
  • 1
    Need to specify a user agent like shown in this answer (tested and it works with your URL) https://stackoverflow.com/a/6905471/11954025 `Invoke-RestMethod` works as well – Daniel Sep 30 '21 at 05:19

1 Answers1

2

Just for completeness sake this script is now returning the file without error, thanks to @Daniel comment.

$wb = New-Object System.Net.WebClient;
$wb.Headers.Add("User-Agent: Other");
$wb.DownloadFile('https://stat.data.abs.gov.au/sdmx-json/data/ABS_BLDG_APPROVALS_LGA2020/1.1.1.110.LGA2020.20660+20740+20830+20910+21110+21180+21450+21610+21890+22170+22310+22490+22670+22750+23110+23270+23430+23670+24130+24210+24330+24410+24600+24650+24850+24970+25060+25150+25250+25340+25710+25900+26080+26170+26350+26490+26980+27070+27260+27350+27450.M/all?detail=Full&dimensionAtObservation=AllDimensions&startPeriod=2020-07&endPeriod=2021-09','C:\temp\test')
sams
  • 439
  • 1
  • 4
  • 17