0

我正在尝试从我的 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.

我究竟做错了什么?

4

1 回答 1

0

由于我的 Powershell 版本,最有效的是 @mario 的解决方案是手动 MIME 构造,如 v5.1 文档的示例 2 所示:https://docs.microsoft.com/en-us/powershell/module/microsoft。 powershell.utility/invoke-webrequest?view=powershell-5.1

干杯。

于 2019-01-28T05:00:24.480 回答