差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
java:ant:http_methods [2018/10/06 22:06] tony [How to?] |
java:ant:http_methods [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 8: | 行 8: | ||
==== Get Artifacts ==== | ==== Get Artifacts ==== | ||
Ant-Http的原始碼可以從GitHub上取得,可以直接透過git從https://github.com/antlibs/ant-http.git clone。我是透過eclipse匯入的,因為它專案libraries是透過ivy resolve,所以整個在eclipse上跑起來沒什麼問題;build ant lib可以直接執行它提供的build.xml,以下是專案結構內容:\\ | Ant-Http的原始碼可以從GitHub上取得,可以直接透過git從https://github.com/antlibs/ant-http.git clone。我是透過eclipse匯入的,因為它專案libraries是透過ivy resolve,所以整個在eclipse上跑起來沒什麼問題;build ant lib可以直接執行它提供的build.xml,以下是專案結構內容:\\ | ||
- | {{:java:ant:ant-http-project-arch.png|}} | + | {{:java:ant:ant-http-project-arch.png|}}\\ |
- | ==== HttpMethods ==== | + | \\ |
- | 在設定上,dist有一個ant-http所提供的範例,所以應該不會有什麼問題。使用的部分我直接提供範例給大家參考: | + | 在設定上,dist有一個ant-http所提供的範例,所以應該不會有什麼問題。使用的部分我直接提供範例給大家參考。 |
+ | ==== HTTP PUT ==== | ||
+ | PUT我用於上傳檔案。source file透過entity指定;如果你的http server需要basic認證,可以使用credentials。 | ||
<code xml> | <code xml> | ||
- | <target name="upload-artifact"> | + | <target name="put-artifact"> |
<http url="http://192.168.1.123/repositories/test_project/branch.properties" | <http url="http://192.168.1.123/repositories/test_project/branch.properties" | ||
method="PUT" printrequestheaders="true" expected="201"> | method="PUT" printrequestheaders="true" expected="201"> | ||
行 20: | 行 22: | ||
</target> | </target> | ||
</code> | </code> | ||
+ | 假如你要上傳的檔案非文字檔而是二進位檔,如執行檔、zip檔等,記得要在entity宣告binary為true: | ||
+ | <code xml> | ||
+ | <entity file="test.zip" binary="true"/> | ||
+ | </code> | ||
+ | ==== HTTP DELETE ==== | ||
<code xml> | <code xml> | ||
<target name="delete-artifact"> | <target name="delete-artifact"> | ||
行 28: | 行 35: | ||
</target> | </target> | ||
</code> | </code> | ||
+ | ==== Others ==== | ||
+ | 預設ant-http會做status code的驗證,假如你不需要這個驗證,可以使用failOnUnexpected屬性: | ||
+ | <code xml> | ||
+ | <http url="http://192.168.1.123/repositories/test_project/branch.properties" | ||
+ | method="DELETE" printrequestheaders="true" failOnUnexpected="false"/> | ||
+ | </code> | ||
===== Reference ===== | ===== Reference ===== | ||
* [[https://github.com/antlibs/ant-http|GitHub Ant-Http]] | * [[https://github.com/antlibs/ant-http|GitHub Ant-Http]] | ||
+ | ===== ===== | ||
+ | ---- | ||
+ | \\ | ||
+ | ~~DISQUS~~ | ||