如何使用AntExec任务调用curl并向RESTAPI发布消息

如何使用AntExec任务调用curl并向RESTAPI发布消息,curl,post,ant,exec,content-type,Curl,Post,Ant,Exec,Content Type,创建了一个Ant任务以发出curl post请求: <target name="invoke-curl" description="Invoke curl using Ant"> <exec executable="curl"> <arg value="-kiv" /> <arg value="-X POST" /> <arg value="-H 'Accept: application

创建了一个Ant任务以发出curl post请求:

<target name="invoke-curl" description="Invoke curl using Ant">
    <exec executable="curl">
        <arg value="-kiv" />
        <arg value="-X POST" />
        <arg value="-H 'Accept: application/json'" />
        <arg value="-H 'Content-Type: application/json'" />        
        <arg value="-d" />
        <arg value="&apos;{&quot;username&quot;:&quot;xyz&quot;,&quot;password&quot;:&quot;XYZ&quot;}&apos;" />
        <arg value="https://hostname:8443/rest/api/login" />        
    </exec>
</target>

虽然它很旧,但您可以试试,例如:

<exec executable="curl">
    <arg value="-kiv" />
    <arg value="-X" />
    <arg value="POST"/>
    <arg value="-H" />
    <arg value="Accept: application/json" />
    <arg value="http://localhost:${diagnose.management.port}/manage/shutdown" />
</exec>


如下图所示更改代码

<target name="invoke-curl" description="Invoke curl using Ant">
        <exec executable="curl">
            <arg value="-kiv" />
            <arg value="-X POST" />
            <arg value="-H" />
            <arg value="Accept: application/json" />
            <arg value="-H" />
            <arg value="Content-Type: application/json" />        
            <arg value="-d" />
            <arg value="&apos;{&quot;username&quot;:&quot;xyz&quot;,&quot;password&quot;:&quot;XYZ&quot;}&apos;" />
            <arg value="https://hostname:8443/rest/api/login" />        
        </exec>
    </target>

默认情况下,许多平台没有安装curl。
要实现跨平台,定制ant任务会更好。使用或编写自己的说明。

需要更多说明
<target name="invoke-curl" description="Invoke curl using Ant">
        <exec executable="curl">
            <arg value="-kiv" />
            <arg value="-X POST" />
            <arg value="-H" />
            <arg value="Accept: application/json" />
            <arg value="-H" />
            <arg value="Content-Type: application/json" />        
            <arg value="-d" />
            <arg value="&apos;{&quot;username&quot;:&quot;xyz&quot;,&quot;password&quot;:&quot;XYZ&quot;}&apos;" />
            <arg value="https://hostname:8443/rest/api/login" />        
        </exec>
    </target>