我正在尝试从我的 Windows 机器上的 Powershell 将文件 HTTP 推送到服务器。服务器正在使用 PHP 脚本(从此处的 w3schools 版本中删除:https ://www.w3schools.com/php/php_file_upload.asp ):
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
使用 w3schools 教程中显示的 HTML 文件和 Chrome 作为浏览器,我可以毫无问题地使用此脚本进行上传。但是,我似乎无法使用 Invoke-WebRequest 上传。
这是我正在使用的命令:
Invoke-WebRequest -InFile "C:\test.txt" -ContentType "text/plain" -Method post -Uri http://example.com/upload/upload.php
和输出的一部分:
StatusCode : 200
StatusDescription : OK
Content : Sorry, there was an error uploading your file.
我究竟做错了什么?