76

ファイルをアップロードするためにHTTPPUTメソッドを使用してサービスを作成しました。

WebブラウザはPUTをサポートしていないので、テストする方法が必要です。それはブラウザからそれを打つPOSTとして素晴らしい働きをします。

更新:これはうまくいったものです。ポスターを試しましたが、フィドラーを使用した場合と同じ問題が発生します。リクエストを作成する方法を知っている必要があります。カールが問題を処理します。

curl -X PUT "localhost:8080/urlstuffhere" -F "file=@filename" -b "JSESSIONID=cookievalue"
4

4 に答える 4

172

私の意見では、このようなテストに最適なツールはcurlです。その--upload-fileオプションは、ファイルをアップロードしますPUT。これはまさにあなたが望むものです(そして、必要に応じてHTTPヘッダーを変更するなど、さらに多くのことを実行できます)。

curl http://myservice --upload-file file.txt
于 2011-02-28T15:40:36.543 に答える
24
curl -X PUT -T "/path/to/file" "http://myputserver.com/puturl.tmp"
于 2018-04-09T09:46:55.940 に答える
1

PHPを使用している場合は、以下のコードを使用してPUTアップロードをテストできます。

#Initiate cURL object
$curl = curl_init();
#Set your URL
curl_setopt($curl, CURLOPT_URL, 'https://local.simbiat.ru');
#Indicate, that you plan to upload a file
curl_setopt($curl, CURLOPT_UPLOAD, true);
#Indicate your protocol
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
#Set flags for transfer
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
#Disable header (optional)
curl_setopt($curl, CURLOPT_HEADER, false);
#Set HTTP method to PUT
curl_setopt($curl, CURLOPT_PUT, 1);
#Indicate the file you want to upload
curl_setopt($curl, CURLOPT_INFILE, fopen('path_to_file', 'rb'));
#Indicate the size of the file (it does not look like this is mandatory, though)
curl_setopt($curl, CURLOPT_INFILESIZE, filesize('path_to_file'));
#Only use below option on TEST environment if you have a self-signed certificate!!! On production this can cause security issues
#curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
#Execute
curl_exec($curl);
于 2021-02-22T11:15:11.317 に答える
-1

の場合、スイッチcurlを使用してみませんか?-dのように:curl -X PUT "localhost:8080/urlstuffhere" -d "@filename"

于 2017-03-16T09:23:56.857 に答える