如何在PowerShell中填写php表单类型:multipart / form-data和多个文件

问题描述 投票:0回答:1

我无法在PowerShell中使用两个文件发布一个php表单

我搜索相当于bash命令:/ usr / bin / curl -F fichier1 = @ / path_to_file1 -F fichier2 = @ / path_to_file2 \ MyUrl.com

Php表单“公式”等两个参数:“fichier1”类型文件和“fichier2”类型文件

我试图遵循What is the right way to POST multipart/form-data using curl?的解决方案,但我有错误消息找不到匹配参数名称'F'的参数我试图使用带有-Infile参数的Invoke-Method但它只接受一个字符串参数和我无法通过我的两个文件路径Hère是我的代码:

$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

php forms powershell multipartform-data
1个回答
0
投票

好的,我找到了解决方案

我已经下载了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
© www.soinside.com 2019 - 2024. All rights reserved.