8

I was trying to run curl command using PowerShell.

below is the curl command

curl --location --request POST "controller/lttrouter/v1/TestResult/process-data-results/" --form "synthesisreport=@"C:\Users\subu\Desktop\testdemo\SynthesisReport.csv";type=text/csv" --form "createdBy=subu" --form "jiraStoryId=LT1235" --form "jiraTaskId=LT1236" --form "tag=demo-test"

Above curl is working on the Command Prompt.

I tried below PowerShell code

$CurlExecutable = "C:\curl-7.65.1-win64-mingw\bin\curl.exe"
$path="C:\Users\subu\Desktop\Test\SynthesisReport.csv"

Write-Host "CurlFile" $CurlFile
$CurlArguments = '--location','--request', 'POST', 
                 '"controller/lttrouter/v1/TestResult/process-data-results/"',
                 '--form', 'synthesisreport=@$path',
                 '--form', 'createdBy=subu',
                 '--form', 'jiraStoryId=LT1235',
                 '--form', 'jiraTaskId=LT1236',
                 '--form', 'tag=demo-test'

& $CurlExecutable @CurlArguments

I am getting below error

curl.exe : curl: (26) Failed to open/read local data from file/application
At line:13 char:1
+ & $CurlExecutable @CurlArguments
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (curl: (26) Fail...ile/application:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Where I am doing the mistake, please suggest.

2
  • PowerShell is not C.. Remove the @ from the line 'synthesisreport=@$path' and use double quotes around it instead of single quotes, so the $path variable gets expanded.
    – Theo
    Jun 13, 2019 at 13:10
  • Refer to this post Using curl to upload POST data with files
    – LF00
    Sep 19, 2019 at 12:09

1 Answer 1

2

Don't use splatting in this case, just pass the argument list ($ instead of @), properly add the quotes and make sure $path gets expanded:

$curlExecutable = "C:\curl-7.65.1-win64-mingw\bin\curl.exe"
$path = "C:\Users\subu\Desktop\Test\SynthesisReport.csv"

Write-Host "CurlFile" $curlExecutable
$curlArguments = "--location","--request", "POST", 
                 "`"controller/lttrouter/v1/TestResult/process-data-results/`"",
                 "--form", "`"synthesisreport=@`"$path`";type=text/csv`"",
                 "--form", "`"createdBy=subu`"",
                 "--form", "`"jiraStoryId=LT1235`"",
                 "--form", "`"jiraTaskId=LT1236`"",
                 "--form", "`"tag=demo-test`""

& $curlExecutable $curlArguments    
2
  • I tried the above code still getting the same error. Additionally, I tried verified the @curlExecutable with this code ` Write-Host @curlArguments` --location --request POST "controller01/lttrouter/v1/TestResult/process-data-results/" --form "synthesisreport="C:\Users\subu\Desktop\Test\SynthesisReport.csv";type=text/csv" --form "createdBy=subu" --form "jiraStoryId=LT1235" --form "jiraTaskId=LT1236" --form "tag=demo-test" Jun 13, 2019 at 12:00
  • 1
    Did you change TestResult to Test on purpose in the path?
    – mhu
    Jun 13, 2019 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.