【问题标题】:Ansible URI Module with multipart/mixed?具有多部分/混合的 Ansible URI 模块?
【发布时间】:2020-12-09 11:07:12
【问题描述】:

我正在尝试使用 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"

【问题讨论】:

    标签: curl ansible uri


    【解决方案1】:

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

    -F, --form

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

    来源: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
    

    另见:

    【讨论】:

    • 您好,感谢您的完整回复。我在这里使用第 3 方提供商提供的 rest 调用 - help.tableau.com/current/api/rest_api/en-us/REST/… 将对此进行尝试,看看它是否会打球。
    • 您可以使用例如验证。 httpbin.org,来自 curl 的请求实际上具有 Content-Type: multipart/mixed。我猜-H 会覆盖-F 的默认值。
    • 感谢您指出@MichałPolitowski,那么我猜Ansible 正在更严格地执行这一点,因为他们的文档指出使用form-multipart 时不能覆盖'Content-Type' 标头 — docs.ansible.com/ansible/latest/collections/ansible/builtin/…
    • @β.εηοιτ.βε 你找到解决方案了吗?我也有与 Tableau API 完全相同的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 2022-11-18
    • 2012-02-14
    相关资源
    最近更新 更多