首页 > 解决方案 > 具有多部分/混合的 Ansible URI 模块?

问题描述

我正在尝试使用 Ansible URI 模块来复制下面的 curl 语句,但我的速度很快。是否支持多部分/混合,如果支持,如何。有什么想法吗?

curl "http://server_address" \
     -X POST \ 
     -H "Auth: blahblahblah" \ 
     -H "Content-Type: multipart/mixed;" \
     -F "request_payload=@pay_file.xml" \ 
     -F "workbook=@file.twb"

标签: curlansibleuri

解决方案


正如 cURL 文档所指出的,您的请求实际上似乎是矛盾的:

-F, --form <名称=内容>

(HTTP SMTP IMAP)对于 HTTP 协议族,这让 curl 模拟用户按下提交按钮的填写表单。这会导致 curl根据RFC 2388使用 Content-Type multipart/form-data发布数据。

来源:https ://curl.se/docs/manpage.html#-F ,强调我的

所以我猜你并没有真正以Content-Type: multipart/mixed.

所以从这里看起来是你正在看的东西:

- uri:
    url: http://example.org
    ## -X POST
    method: POST     
    ## -H "Auth: blahblahblah"                                  
    url_username: some_user
    url_password: some_password
    ## You might also need this one
    # force_basic_auth: true
    ## Content-type as forced by cURL when using -F
    body_format: form-multipart
    body:
      ## -F "request_payload=@pay_file.xml"
      request_payload: 
        content: "{{ lookup('file', 'pay_file.xml') }}"
        filename: pay_file.xml
        mime_type: application/xml
      ## -F "workbook=@file.twb"
      workbook: 
        content: "{{ lookup('file', 'file.twb') }}"
        filename: file.twb
        mime_type: application/twb

另见:


推荐阅读