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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在PowerShell中填写php表单类型:multipart / form-data和多个文件相关的知识,希望对你有一定的参考价值。

我无法在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

答案

好的,我找到了解决方案

我已经下载了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中填写php表单类型:multipart / form-data和多个文件的主要内容,如果未能解决你的问题,请参考以下文章

如何创建一个在 php 中自动填写表单的唯一链接?

用户通过PHP填写表单后如何自动生成页面?

PHP100例PHP处理表单数据

如何创建表,在用户提交表单时填写行

使用 jQuery 动态填写表单值

用 PHP 填写 PDF 表单 [关闭]