As part of my Ant build process, I'd like to upload files to a webserver via HTTP Post. Ant only comes with an HTTP Get task. However, Ant Contrib seems to have an HTTP Post task. The problem is that it doesn't have开发者_StackOverflow any Basic Authentication (like get does) or any way to specify a file upload (despite what the docs say, "rawFile" is not part of the distro).
My question is: does Ant Contrib's Post task actually support what I want, but in a non-obvious way (perhaps I have to do it by hand)? Or is there some other way to do this?
I have created an Apache 2.0 licensed, full featured and easy to use ant http task. It utilizes code java.net.* classes and has no third party library dependencies.
It can do POST/PUT with files or in-line entities, and has flexible options for setting required headers, authentication and status code checking for build failure on unexpected results.
http://missinglinkcode.wordpress.com/2011/03/15/apache-ant-http-task/
Use the curl program called via an ANT exec task.
For curl examples read this answer
A new ant http task named "Missing Link" has been announced on the Ant User List, give it a try = http://code.google.com/p/missing-link/
There's an http post task in Antelope but it doesn't appear to support Basic Authentication. :/
There's also an AntLib in the ant sandbox here that claims to do HTTP get and post. However, its authentication is broken also.
I made a patch for ant-contrib that adds basic authentication to the post task. Hopefully it gets included in the trunk. In the meantime, you can build it from source and apply the patch yourself:
http://sourceforge.net/tracker/?func=detail&aid=3110414&group_id=36177&atid=416922
Once you've installed the new ant-contrib.jar, just add username and password attributes to the post task and it should work just fine. The file uploading, I dunno...
There's a bunch of ant tasks based upon jakarta commons http client :
http://fikin-ant-tasks.sourceforge.net/
also providing a http post task with authentication.
When using ant with exec you will open a new process outside the java vm. IMO external processes should be avoided if possible.
P.S. : if fikin ant tasks / http post with basic authentication is broken i would prefer writing a java class or even my own task with jakarta commons, see jakarta commons http client , sample for basic authentication 2
so it may run in the same vm as ant or maybe in a forked java process
you'll find several examples for file upload with jakarta commons httpclient via google..
精彩评论