wget command taking input as file and file must contain url and string argument

StackOverflow https://stackoverflow.com/questions/21898749

  •  14-10-2022
  •  | 
  •  

質問

Need a syntax example for sending input file using wget command. the input file has an URL and a string argument. Examples will be helpful. Thanks in advance.

役に立ちましたか?

解決

It is possible to do this with wget only. At least with version 1.13.4 and maybe others. The --post-file option allows you to specify a file to send, so long as the postdata file is constructed properly.

I have also tested this with binary files and it works as expected. You do NOT need to base64 encode the file, but you do need to ensure your file does not contain the boundary.

The minimum command required to make this work would be:

wget --header="Content-type: multipart/form-data boundary=FILEUPLOAD" --post-file postfile http://domain/uploadform

and the postdata file would need to contain something like:

--FILEUPLOAD Content-Disposition: form-data; name="comment"

I love uploading files!

--FILEUPLOAD Content-Disposition: form-data; name="uploadFile"; filename="myfile.bin"; Content-Type: application/octet-stream Media Type: application/octet-stream

Give me some automated file upload action!

--FILEUPLOAD--

A number of details are important here:

Lines in the post data file are terminated with \r\n. The only exception is data inside the file context. Every BOUNDARY attribute in the postdata must match the BOUNDARY value in the call to wget. (FILEUPLOAD in the example) All boundaries are prefixed with two hyphens "--" and terminated with \r\n The last boundary is suffixed with two extra hyphens "--" and terminated with \r\n Each piece of data, file content or parameter value, is surrounded by an empty line "\r\n"

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top