使用 curl 只需设置标题,例如,-H 'Content-Type: text/html':
cat 1.html | curl --silent --show-error --fail -X PUT -H 'Content-Type: text/html' -d @- localhost:8000
在你得到的服务器上:
Content-Type: text/html
通常(与浏览器一样),文件上传需要 method=post 和 enctype="multipart/form-data"。然后可以为每个部分设置 Content-Type。使用 curl 你可以这样做:
curl ... -F "file=@-;type=text/html" <destination>
在您将获得的服务器上:
Content-Type: multipart/form-data; boundary=------------------------2fa1094be9afdaa6
...
--------------------------2fa1094be9afdaa6
Content-Disposition: form-data; name="file"; filename="-"
Content-Type: text/html
...
您需要从 wget 标头中提取相关的内容类型。也许通过使用 --save-headers 选项?首先将内容读入变量file,将标头字段值提取到变量content_type,然后将除标头之外的所有内容传递给curl,您现在可以使用上面的$content_type 调用它:
wget ... | { file=$(</dev/stdin); content_type=$(echo "$file" | sed -n '1,/^\r$/ { /^Content-Type: /{ s/.*: \(.*\)/\1/p; q } }'); echo "$file" | sed '1,/^\r$/d' | curl ... }