如何从mule4调用curl命令 [英] how to call curl command from mule4

查看:90
本文介绍了如何从mule4调用curl命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将文件上传到API.我有curl命令,可以通过邮递员成功加载.但是现在我想通过MuleSoft调用这个curl命令吗?我们该怎么做?我尝试了执行组件(通过Groovy引擎).但是文件正在加载,控制台日志中也没有错误.

I have to upload a file to an API. I have the curl command for it and I am able to load through postman successfully. But now I want to call this curl command through MuleSoft? how can we do it? I tried through Execute component (through Groovy engine).But the file is getting loaded and there is no error also in the console log.

CURL命令curl -H"apiAccessKeyId:USERNAME" -H"apiSecretAccessKey:PASSWORD" -H"Accept:application/json" --form"file = @ C:\ Files \ medialist.csv" --form"params = {Type:Import}"-X POST http://mysuperserver/media/upload/

CURL COMMAND curl -H "apiAccessKeyId:USERNAME" -H "apiSecretAccessKey:PASSWORD" -H "Accept:application/json" --form "file=@C:\Files\medialist.csv" --form "params={Type:Import}" -X POST http://mysuperserver/media/upload/

建议吗?

推荐答案

您不应尝试从Mule应用程序执行curl命令.我强烈不鼓励这样做.相反,您应该使用Mule组件和连接器来再现相同的请求.

You should not try to execute the curl command from the Mule application. I strongly discourage of doing that. Instead you should use Mule components and connectors to reproduce the same requests.

对于这种特定情况,您可以使用文件连接器来读取文件,可以使用DataWeave转换来生成带有附件的多部分表单数据请求,并且可以使用HTTP请求连接器来发送相同的请求并重现相同的HTTP请求,卷曲.

For this specific situation you can use the File connector to read the file, a DataWeave transform to generate the multipart form data request with the attachment, and the the HTTP Request connector to send the same request and reproduce the same HTTP Request that curl performs.

例如,它在XML视图中看起来与此类似:

For example it would look similar to this in the XML view:

    <flow name="so-file-http-request-sendFlow">
        <file:read doc:name="Read" path="c:\files\medialist.csv"/>
        <ee:transform doc:name="Transform Message">
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data
---
{
    parts : {
        params : {
          headers : {
            "Content-Type": "text/plain"
          },
          content : "{Type=import}"
        },
        file : {
              headers : {
                "Content-Disposition" : {
                    "name": "file",
                    "filename": "medialist.csv"
                },
                "Content-Type" : "application/csv"
              }     
            }
        }      
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <http:request method="POST" doc:name="Request" config-ref="HTTP_Request_configuration" path="/media/upload/">
            <http:headers ><![CDATA[#[output application/java
---
{
    Accept : "application/json",
    apiAccessKeyId : "USERNAME",
    apiSecretAccessKey : "PASSWORD"
}]]]></http:headers>
        </http:request>
    </flow>

您可以使用 HTTP有线日志记录查看请求是否与CURL发送的内容匹配.

You can use the HTTP wire logging to see if the request matches what CURL sends.

这篇关于如何从mule4调用curl命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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