How to use ant exec task to invoke curl and POST a message to rest api
Created an Ant task to make a curl post request :
<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="'{"username":"xyz","password":"XYZ"}'" />
<arg value="https://hostname:8443/rest/api/login" />
</exec>
</target>
Interestingly the API supports only "Content-Type: application/json". But curl seems to be adding the "Content-Type: application/x-www-form-urlencoded" in addition to the header sent as a parameter to Curl. The API does not seem to like this and returns "< HTTP/1.1 415 Unsupported Media Type". It looks like curl is finding the data encoded and hence setting this default header on its own. So is there a way to prevent curl from setting this default "Content-Type: application/x-www-form-urlencoded" and just use the header set as a parameter to curl command.
User-Agent: curl/7.51.0
Accept: */*
'Accept: application/json'
'Content-Type: application/json'
Content-Length: 52
Content-Type: application/x-www-form-urlencoded
链接地址: http://www.djcxy.com/p/1344.html