Bash script into PowerShell (curl into Invoke-WebRequest)

sigfried 81 Reputation points
2022-08-30T08:26:26.04+00:00

Hello, I need to convert a bash script into PowerShell. The script has a line where it uses "curl" in this way:

curl -x proxy:80 -k https://xxxxxxxxxxxxxx.php -d strFrom= -d strCountry= -d strCode= > /dir1/dir2/download.xml  

I'm using Invoke-WebRequest to translate this and it's pretty ok, except for the -d strFrom= -d strCountry= -d strCode= part for which I cannot find the right arguments. The bash script is telling to download the most recent (-d strFrom=) download.xml file available, from any country (-d strCountry=) and for all currency (-d strCode=). Any idea on how to translate that into Invoke-WebRequest? If I use this line below, the xml file downloaded is empty, while the curl line downloads a file with content:

Invoke-WebRequest -Proxy proxy:80 -Uri "https://xxxxxxxxxxxxxx.php" -Method Get -OutFile /dir1/dir2/download.xml  
Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2022-08-30T11:59:26.497+00:00

    See this: https://stackoverflow.com/questions/17325293/invoke-webrequest-post-with-parameters

    If Get doesn't work, try using Post.

    $postParams = @{strFrom='';strCountry='';strCode=''}   
    Invoke-WebRequest -Proxy proxy:80 -Uri "https://xxxxxxxxxxxxxx.php" -Method Get -OutFile /dir1/dir2/download.xml -Body $postParams  
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.