如何在 powershell 中使用多个文件填写 php 表单类型:multipart/form-data
How to fill php form type:multipart/form-data with multiple files in powershell
我无法在 powershell 中 POST 一个包含两个文件的 php 表单
我搜索了 bash 命令的等价物:
/usr/bin/curl -F fichier1=@/path_to_file1 -F fichier2=@/path_to_file2\MyUrl.com
Php形式"formulaire"等待两个参数:
"fichier1" 类型文件
和 "fichier2" 输入文件
我已尝试遵循 What is the right way to POST multipart/form-data using curl? 的解决方案,但出现错误消息找不到与参数名称匹配的参数 'F'
我尝试将 Invoke-Method 与 -Infile 参数一起使用,但它只接受一个字符串参数,我无法传递我的两个文件路径
这是我的代码:
$Uri = "//MyUrl.com/backups/uploadLogsVms.php"
$filePath="C:\backup_points.csv"
$filePath2="C:\PROTECTED_VMS_JOB_SCHEDULE_2018_12_10.csv"
curl -v -F fichier1=@"$filePath" -F fichier2=@"$filePath2"
我希望填写下面的表格并使用 powershell 脚本按下按钮 boutEnvoyer:
<body>
<form name='formulaire' id='formulaire' method='post' action='/backups/uploadLogsVms.php' enctype='multipart/form-data'>
<input type='file' name='fichier1' id='fichier' size='60' /><br />
<input type='file' name='fichier2' id='fichier' size='60' /><br />
<input type='submit' class='bouton' id='boutEnvoyer' value='Envoyer' />
</form>
</body></html>
相当于我的 bash 命令 /usr/bin/curl -F fichier1=@/path_to_file1 -F fichier2=@/path_to_file2 http://MyUrl.com/backups/uploadLogs.php
好的,我找到了解决方案
我已经下载了 powershell 6.2 版本 powershell 6.2 preview,现在 -Form 参数可以使用了!
并且我将我的代码更正为
$Uri = 'http://MyUrl.com/backups/uploadLogsVms.php'
$Form = @{
fichier1 = Get-Item -Path 'C:\users\ADM_2N\Desktop\PROTECTED_VMS_JOB_SCHEDULE_2018_12_10.csv'
fichier2 = Get-Item -Path 'C:\users\adm_2n\Desktop\backup_points.csv'
}
$Result = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form
我无法在 powershell 中 POST 一个包含两个文件的 php 表单
我搜索了 bash 命令的等价物: /usr/bin/curl -F fichier1=@/path_to_file1 -F fichier2=@/path_to_file2\MyUrl.com
Php形式"formulaire"等待两个参数: "fichier1" 类型文件 和 "fichier2" 输入文件
我已尝试遵循 What is the right way to POST multipart/form-data using curl? 的解决方案,但出现错误消息找不到与参数名称匹配的参数 'F' 我尝试将 Invoke-Method 与 -Infile 参数一起使用,但它只接受一个字符串参数,我无法传递我的两个文件路径 这是我的代码:
$Uri = "//MyUrl.com/backups/uploadLogsVms.php"
$filePath="C:\backup_points.csv"
$filePath2="C:\PROTECTED_VMS_JOB_SCHEDULE_2018_12_10.csv"
curl -v -F fichier1=@"$filePath" -F fichier2=@"$filePath2"
我希望填写下面的表格并使用 powershell 脚本按下按钮 boutEnvoyer:
<body>
<form name='formulaire' id='formulaire' method='post' action='/backups/uploadLogsVms.php' enctype='multipart/form-data'>
<input type='file' name='fichier1' id='fichier' size='60' /><br />
<input type='file' name='fichier2' id='fichier' size='60' /><br />
<input type='submit' class='bouton' id='boutEnvoyer' value='Envoyer' />
</form>
</body></html>
相当于我的 bash 命令 /usr/bin/curl -F fichier1=@/path_to_file1 -F fichier2=@/path_to_file2 http://MyUrl.com/backups/uploadLogs.php
好的,我找到了解决方案
我已经下载了 powershell 6.2 版本 powershell 6.2 preview,现在 -Form 参数可以使用了!
并且我将我的代码更正为
$Uri = 'http://MyUrl.com/backups/uploadLogsVms.php'
$Form = @{
fichier1 = Get-Item -Path 'C:\users\ADM_2N\Desktop\PROTECTED_VMS_JOB_SCHEDULE_2018_12_10.csv'
fichier2 = Get-Item -Path 'C:\users\adm_2n\Desktop\backup_points.csv'
}
$Result = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form