使用 Wget 发布请求? [英] Post request with Wget?

查看:43
本文介绍了使用 Wget 发布请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 wget 将图片上传到远程服务器,使用身份验证令牌AUTH_1624582364932749DFHDD"到test"文件夹.

I want to use wget to upload a picture to a distant server, using an authentication token, 'AUTH_1624582364932749DFHDD', to the 'test' folder.

此命令不起作用(授权失败),我想确保它与语法无关:

This command doesn't work (authorization failed), and I want to make sure that it's not about syntax:

wget --post-file=nature.jpg http://ipadress:8080/v1/AUTH_test/test/ --post-data="AUTH_1624582364932749DFHDD"

有什么建议吗?

推荐答案

Wget 目前不支持multipart/form-data";数据.--post-file 不是用于将文件作为表单附件传输,它需要格式为:key=value&otherkey=example 的数据.发对应的header其实也可以发其他格式(json).

Wget currently doesn't not support "multipart/form-data" data. --post-file is not for transmitting files as form attachments, it expects data with the form: key=value&otherkey=example. It is actually possible to post other formats (json) if you send the corresponding header.

--post-data--post-file 工作方式相同:唯一的区别是 --post-data允许您在命令行中指定数据,而 --post-file 允许您指定包含要发送的数据的文件的路径.

--post-data and --post-file work the same way: the only difference is that --post-data allows you to specify the data in the command line, while --post-file allows you to specify the path of the file that contain the data to send.

文档如下:

 --post-data=string
       --post-file=file
           Use POST as the method for all HTTP requests and send the specified data
           in the request body.  --post-data sends string as data, whereas
           --post-file sends the contents of file.  Other than that, they work in
           exactly the same way. In particular, they both expect content of the
           form "key1=value1&key2=value2", with percent-encoding for special
           characters; the only difference is that one expects its content as a
           command-line parameter and the other accepts its content from a file. In
           particular, --post-file is not for transmitting files as form
           attachments: those must appear as "key=value" data (with appropriate
           percent-coding) just like everything else. Wget does not currently
           support "multipart/form-data" for transmitting POST data; only
           "application/x-www-form-urlencoded". Only one of --post-data and
           --post-file should be specified.

关于您的身份验证令牌,它应该在标头、url 路径或数据本身中提供.这必须在您使用的服务的文档中的某处指明.在 POST 请求中,就像在 GET 请求中一样,您必须使用键和值指定数据.这样服务器将能够接收具有特定名称的多个信息.与变量类似.

Regarding your authentication token, it should either be provided in the header, in the path of the url, or in the data itself. This must be indicated somewhere in the documentation of the service you use. In a POST request, as in a GET request, you must specify the data using keys and values. This way the server will be able to receive multiple information with specific names. It's similar with variables.

因此,您不能只向服务器发送魔术令牌,您还需要指定密钥的名称.如果密钥是token",那么它应该是token=YOUR_TOKEN.

Hence, you can't just send a magic token to the server, you also need to specify the name of the key. If the key is "token", then it should be token=YOUR_TOKEN.

wget --post-data 'user=foo&password=bar' http://example.com/auth.php

此外,如果可以,您应该考虑使用 curl,因为使用它发送文件更容易.互联网上有很多这样的例子.

Also, you should consider using curl if you can because it is easier to send files using it. There are many examples on the Internet for that.

这篇关于使用 Wget 发布请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆