Lines 54-59
Link Here
|
54 |
import org.apache.commons.httpclient.methods.PostMethod; |
54 |
import org.apache.commons.httpclient.methods.PostMethod; |
55 |
import org.apache.commons.httpclient.methods.PutMethod; |
55 |
import org.apache.commons.httpclient.methods.PutMethod; |
56 |
import org.apache.commons.httpclient.methods.RequestEntity; |
56 |
import org.apache.commons.httpclient.methods.RequestEntity; |
|
|
57 |
import org.apache.commons.httpclient.methods.StringRequestEntity; |
57 |
import org.apache.commons.httpclient.methods.TraceMethod; |
58 |
import org.apache.commons.httpclient.methods.TraceMethod; |
58 |
import org.apache.commons.httpclient.methods.multipart.FilePart; |
59 |
import org.apache.commons.httpclient.methods.multipart.FilePart; |
59 |
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; |
60 |
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; |
Lines 313-323
Link Here
|
313 |
} |
314 |
} |
314 |
} |
315 |
} |
315 |
else { |
316 |
else { |
316 |
// Set the content type |
317 |
// Check if the header manager had a content type header |
317 |
post.setRequestHeader(HEADER_CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED); |
318 |
// This allows the user to specify his own content-type for a POST request |
|
|
319 |
Header contentTypeHeader = post.getRequestHeader(HEADER_CONTENT_TYPE); |
320 |
boolean hasContentTypeHeader = contentTypeHeader != null && contentTypeHeader.getValue() != null && contentTypeHeader.getValue().length() > 0; |
318 |
|
321 |
|
319 |
// If there are no arguments, we can send a file as the body of the request |
322 |
// If there are no arguments, we can send a file as the body of the request |
320 |
if(getArguments().getArgumentCount() == 0 && getSendFileAsPostBody()) { |
323 |
if(getArguments().getArgumentCount() == 0 && getSendFileAsPostBody()) { |
|
|
324 |
if(!hasContentTypeHeader) { |
325 |
// Allow the mimetype of the file to control the content type |
326 |
if(getMimetype() != null && getMimetype().length() > 0) { |
327 |
post.setRequestHeader(HEADER_CONTENT_TYPE, getMimetype()); |
328 |
} |
329 |
else { |
330 |
post.setRequestHeader(HEADER_CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED); |
331 |
} |
332 |
} |
333 |
|
321 |
FileRequestEntity fileRequestEntity = new FileRequestEntity(new File(getFilename()),null); |
334 |
FileRequestEntity fileRequestEntity = new FileRequestEntity(new File(getFilename()),null); |
322 |
post.setRequestEntity(fileRequestEntity); |
335 |
post.setRequestEntity(fileRequestEntity); |
323 |
|
336 |
|
Lines 327-347
Link Here
|
327 |
else { |
340 |
else { |
328 |
// In an application/x-www-form-urlencoded request, we only support |
341 |
// In an application/x-www-form-urlencoded request, we only support |
329 |
// parameters, no file upload is allowed |
342 |
// parameters, no file upload is allowed |
330 |
|
343 |
if(!hasContentTypeHeader) { |
|
|
344 |
// Set the content type |
345 |
post.setRequestHeader(HEADER_CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED); |
346 |
} |
347 |
|
331 |
// If a content encoding is specified, we set it as http parameter, so that |
348 |
// If a content encoding is specified, we set it as http parameter, so that |
332 |
// the post body will be encoded in the specified content encoding |
349 |
// the post body will be encoded in the specified content encoding |
333 |
final String contentEncoding = getContentEncoding(); |
350 |
final String contentEncoding = getContentEncoding(); |
334 |
if(contentEncoding != null && contentEncoding.trim().length() > 0) { |
351 |
if(contentEncoding != null && contentEncoding.trim().length() > 0) { |
335 |
post.getParams().setContentCharset(contentEncoding); |
352 |
post.getParams().setContentCharset(contentEncoding); |
336 |
} |
353 |
} |
337 |
|
354 |
|
338 |
PropertyIterator args = getArguments().iterator(); |
355 |
// If none of the arguments have a name specified, we |
339 |
while (args.hasNext()) { |
356 |
// just send all the values as the post body |
340 |
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue(); |
357 |
if(!getSendParameterValuesAsPostBody()) { |
341 |
post.addParameter(arg.getName(), arg.getValue()); |
358 |
// It is a normal post request, with parameter names and values |
|
|
359 |
PropertyIterator args = getArguments().iterator(); |
360 |
while (args.hasNext()) { |
361 |
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue(); |
362 |
post.addParameter(arg.getName(), arg.getValue()); |
363 |
} |
342 |
} |
364 |
} |
|
|
365 |
else { |
366 |
// Just append all the parameter values, and use that as the post body |
367 |
StringBuffer postBody = new StringBuffer(); |
368 |
PropertyIterator args = getArguments().iterator(); |
369 |
while (args.hasNext()) { |
370 |
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue(); |
371 |
postBody.append(arg.getValue()); |
372 |
} |
373 |
StringRequestEntity requestEntity = new StringRequestEntity(postBody.toString(), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), post.getRequestCharSet()); |
374 |
post.setRequestEntity(requestEntity); |
375 |
} |
343 |
|
376 |
|
344 |
// If the Multipart is repeatable, we can send it first to |
377 |
// If the request entity is repeatable, we can send it first to |
345 |
// our own stream, so we can return it |
378 |
// our own stream, so we can return it |
346 |
if(post.getRequestEntity().isRepeatable()) { |
379 |
if(post.getRequestEntity().isRepeatable()) { |
347 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
380 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |