通过 cURL 发布 zip 文件提供二进制输出

Posting a zip file via cURL gives a binary output

我正在使用允许我使用 POST 请求更新 运行 虚拟服务的虚拟化软件。 post 请求在通过网络浏览器中提供的 UI 完成时起作用。它还会在网页上生成一个 curl 命令。

curl -X POST "http://localhost:1505/lisa-virtualize-invoke/api/v3/vses/VSE/services/API_Test_22" -H  "accept: application/json" -H  "Content-Type: multipart/form-data" -F "deploy=true" -F "inputFile1=@updateCustomer.zip;type=application/x-zip-compressed"

然而,当我尝试在 bash 中使用提供的 curl 命令时,它不起作用。我需要能够对 jenkinsfile 使用 curl。

我尝试了 'inputFile1' 的不同变体,例如:

-F "inputFile1=@updateCustomer.zip;type=application/x-zip-compressed"
-F "inputFile1=@updateCustomer.zip"

在 GitBash 中,我得到了一个乱码的非 ASCII 字符作为我的输出。

在 Ubuntu 终端我得到一个不同的错误:

curl -X POST -H "authorization: Basic xxx"  "http://10.0.2.2:1505/lisa-virtualize-invoke/api/v3/vses/VSE/services/API_Test_22" -H  "accept: application/zip" -H  "Content-Type: multipart/form-data" -F "deploy=true" -F "inputFile1=@\"updateCustomer.zip\""
Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.

我在 Jenkins 中的输出是:

+ curl -X POST -H authorization: Basic xxx http://10.0.2.2:1505/lisa-virtualize-invoke/api/v3/vses/VSE/services/API_Test_22 -H accept: application/zip -H Content-Type: multipart/form-data -F deploy=true -F inputFile1=@updateCustomer.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed

 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 63261    0     0  100 63261      0  52325  0:00:01  0:00:01 --:--:-- 52325
100 63261    0     0  100 63261      0  28599  0:00:02  0:00:02 --:--:-- 28599
100 63261    0     0  100 63261      0  19682  0:00:03  0:00:03 --:--:-- 19689
100 63261    0     0  100 63261      0  15004  0:00:04  0:00:04 --:--:-- 15008
100 63261    0     0  100 63261      0  12121  0:00:05  0:00:05 --:--:-- 12121
100 63261    0     0  100 63261      0  10165  0:00:06  0:00:06 --:--:--     0
100 63971    0   710  100 63261    103   9220  0:00:06  0:00:06 --:--:--   152PK�S�N    .maraudit����n�q�w � �4���g���ؤ��(�T�l�o @�1r�~����} &-������U�ƨ���������>���������o�_��g��W�����?���_~�����?��7��~˟����7�����7����?���_�~�B��?��/b����2��h���C�!���������������/ ...

二进制输出是由-H "accept: application/zip"引起的。用 -H "accept: application/json" 替换后,我不再有这个问题了。