powershell - 无法从文件/应用程序打开/读取本地数据

标签 powershell http curl post

我试图运行 curl使用 PowerShell 命令。

下面是 curl命令

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"

以上 curl正在处理命令提示符。

我试过下面的 PowerShell 代码
$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

我得到以下错误

curl.exe : curl: (26) 无法从文件/应用程序打开/读取本地数据
在行:13 字符:1
+ & $CurlExecutable @CurlArguments
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (curl: (26) Fail...ile/application:String) [], RemoteException
+ FullQualifiedErrorId : NativeCommandError

我在哪里做错了,请提出建议。

最佳答案

在这种情况下不要使用 splatting,只需传递参数列表( $ 而不是 @ ),正确添加引号并确保 $path 得到扩展:

$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    

关于powershell - 无法从文件/应用程序打开/读取本地数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56577058/

相关文章:

Angular6如何测试一系列http请求

apache - HTTP2 可用,但服务器拒绝使用它,为什么会这样?

php - 当图像不存在时使用哪种方法

powershell - 列出 UNC 根文件夹中的文件夹和文件

powershell - 将用户名和密码添加到Powershell脚本

javascript - Angularjs $http.get 方法不起作用

php - 将 curl 命令转换为 php curl

powershell - 如何使用Powershell处理自定义日志数据?

powershell - 在PowerShell中获取字符串的权利

javascript - 本地调试包含协议(protocol)相关 URL 的网页的提示