1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
HTTP Post</title>
<meta content="DocBook XSL Stylesheets V1.60.1" name="generator">
<link rel="home" href="index.html" title="Antelope Users Guide">
<link rel="up" href="bk03.html" title="Additional Ant Tasks">
<link rel="previous" href="bk03ch11.html" title="Chapter 11. Math">
<link rel="next" href="bk03ch13.html" title="Chapter 13. SSH and SCP">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="chapter" lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="post">
</a>
HTTP Post</h2>
</div>
</div>
<div>
</div>
</div>
<p>
The Post task is a companion to the standard Ant "Get" task. This task does a post and does not necessarily expect anything in return. Almost always, there will be some sort of returned data, this can be logged or written to a file if needed.
</p>
<p>
Basically, an HTTP POST sends name/value pairs to a web server. A very common usage is for html forms for submitting data. A typical use of this task is to send data to a servlet for updating a web page with the status of a build.
</p>
<p>
This task handles cookies correctly, which is useful for websites that set a session id to track logins or whatever. This means that if you do several posts in a row, cookies gathered from the first post will be returned with subsequent posts.
</p>
<p>
The Post task has three ways of specifying the data to be posted. Nested "prop" elements can be used. A "prop" element represents a single name/value pair. The second way is to specify a property file as an attribute to the Post. All properties from the file will be sent as part of the Post data. The third way is to just type in some defined Ant properties. Is it allowed to use all three ways at once, that is, read some properties from a file, specify others via "prop" elements, and just type in some Ant properties.
</p>
<p>
<div class="table">
<a name="N10A61">
</a>
<p class="title">
<b>
Table 12.1. Post Task Attributes</b>
</p>
<table summary="Post Task Attributes" border="1">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>
Attribute</th>
<th>
Description</th>
<th>
Default</th>
<th>
Required</th>
</tr>
</thead>
<tbody>
<tr>
<td>
to</td>
<td>
The URL of the remote server to send the post.</td>
<td>
None</td>
<td>
Yes</td>
</tr>
<tr>
<td>
encoding</td>
<td>
Character encoding for the name/value pairs.</td>
<td>
UTF-8</td>
<td>
No</td>
</tr>
<tr>
<td>
logfile</td>
<td>
The name of a file to write any response to. Ignored if wantresponse is set to false.</td>
<td>
None</td>
<td>
No</td>
</tr>
<tr>
<td>
property</td>
<td>
The name of a property to write any response to. Ignored if wantresponse is set to false.
</td>
<td>
None</td>
<td>
No</td>
</tr>
<tr>
<td>
append</td>
<td>
Should an existing log file be appended to or overwritten?</td>
<td>
True, append to an existing file.</td>
<td>
No</td>
</tr>
<tr>
<td>
file</td>
<td>
A file to read POST data from. All Ant properties contained in this file will be resolved (that is, ${} syntax will be expanded to their values) prior to sending the file contents.</td>
<td>
None</td>
<td>
No</td>
</tr>
<tr>
<td>
rawFile</td>
<td>
Should the file be trated as raw file instead of property-like file. True - send the content of the file directly to http-post, all properties set by 'property' are ignored!<br/>
Has only impact when the property 'file' is specified.</td>
<td>
False, treat file as property-like</td>
<td>
No</td>
</tr>
<tr>
<tr>
<td>
rawFileNoEncoding</td>
<td>
Don't encode the raw file prior to sending http post request.<br/>
Has only impact when the property 'rawFile' is specified.</td>
<td>
False, http-encode the content of the file</td>
<td>
No</td>
</tr>
<tr>
<td>
maxwait</td>
<td>
The maximum amount of time in seconds to wait for the data to be sent or for a response from the remote server. Setting this to zero means wait forever.</td>
<td>
180 (3 minutes)</td>
<td>
No</td>
</tr>
<tr>
<td>
wantresponse</td>
<td>
Whether to wait for a response from the remote server or not. In many cases this can greatly improve the performance of the build script as the server response may be large and useless to the script. Use this with caution - while the response from the server may not be required for the client, the server may require that the client accept the response prior to processing the post data.</td>
<td>
true</td>
<td>
No</td>
</tr>
<tr>
<td>
failonerror</td>
<td>
Whether the build should fail if the post fails.</td>
<td>
false</td>
<td>
No</td>
</tr>
</tbody>
</table>
</div>
</p>
<p>
Post supports nested "prop" elements. As an HTTP POST basically sends a list of names and values, the "prop" element represents one name/value pair. A Post may contain any number of "prop" elements.
</p>
<p>
<div class="table">
<a name="N10ABF">
</a>
<p class="title">
<b>
Table 12.2. Prop Attributes</b>
</p>
<table summary="Prop Attributes" border="1">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>
Attribute</th>
<th>
Description</th>
<th>
Default</th>
<th>
Required</th>
</tr>
</thead>
<tbody>
<tr>
<td>
name</td>
<td>
The name of a property to post.</td>
<td>
None</td>
<td>
Yes</td>
</tr>
<tr>
<td>
value</td>
<td>
The value associated with the name.</td>
<td>
None</td>
<td>
No</td>
</tr>
</tbody>
</table>
</div>
</p>
<p>
The "value" attribute is not strictly required. This provides a short-cut method in cases where the property data is an already-defined Ant property. Suppose the build file has this property defined:
</p>
<p>
<table border="0" bgcolor="#E0E0E0">
<tr>
<td>
<pre class="programlisting">
<property name="src.dir" value="/home/user/project/src"/>
</pre>
</td>
</tr>
</table>
</p>
<p>
Then the following are equivalent:
</p>
<p>
<table border="0" bgcolor="#E0E0E0">
<tr>
<td>
<pre class="programlisting">
<prop name="src.dir"/>
<prop name="src.dir" value="${src.dir}"/>
<prop name="src.dir" value="/home/user/project/src"/>
</pre>
</td>
</tr>
</table>
</p>
<p>
Defined Ant properties can be entered directly into the post element. Again, suppose the build file has this property defined:
</p>
<p>
<table border="0" bgcolor="#E0E0E0">
<tr>
<td>
<pre class="programlisting">
<property name="src.dir" value="/home/user/project/src"/>
</pre>
</td>
</tr>
</table>
</p>
<p>
Then the following are equivalent:
</p>
<p>
<table border="0" bgcolor="#E0E0E0">
<tr>
<td>
<pre class="programlisting">
${src.dir}
<prop name="src.dir"/>
<prop name="src.dir" value="${src.dir}"/>
<prop name="src.dir" value="/home/user/project/src"/>
</pre>
</td>
</tr>
</table>
</p>
<p>
I googled for the URL in the following example.
</p>
<p>
<table border="0" bgcolor="#E0E0E0">
<tr>
<td>
<pre class="programlisting">
<property name="test.val" value="here's my test value"/>
<property name="test.val2" value="second test value"/>
<post to="http://wwwj.cs.unc.edu:8888/tang/servlet/tangGetPostServlet"
verbose="true">
<prop name="prop1" value="val1 ${test.val}"/>
<prop name="prop2" value="val1 value 2"/>
<prop name="prop3" value="val got some spaces %funky ^$* chars"/>
<prop name="prop4" value="&amp; do an ampersand like this &amp;amp; or
Ant will whine"/>
<prop name="thanks" value="dude, thanks for the echo server!"/>
<prop name="test.val"/>
${test.val2}
</post>
</pre>
</td>
</tr>
</table>
</p>
</div>
<hr>
<p align="center">Copyright © 2003 Ant-Contrib Project. All
rights Reserved.</p>
</body>
</html>
|