PostMethod postMethod = ...; postMethod.setFollowRedirects(true)
/** Execute a POST request and check status * @return the HttpMethod executed * @throws IOException */ public HttpMethod assertPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage) throws IOException { final PostMethod post = new PostMethod(url); post.setFollowRedirects(false); if(postParams!=null) { final NameValuePair [] nvp = {}; post.setRequestBody(postParams.toArray(nvp)); } final int status = httpClient.executeMethod(post); if(assertMessage == null) { assertEquals(expectedStatusCode, status); } else { assertEquals(assertMessage, expectedStatusCode, status); } return post; }
/** Upload multiple files to file node structures */ public void uploadToFileNodes(String url, File[] localFiles, String[] fieldNames, String[] typeHints) throws IOException { List<Part> partsList = new ArrayList<Part>(); for (int i=0; i < localFiles.length; i++) { Part filePart = new FilePart(fieldNames[i], localFiles[i]); partsList.add(filePart); if (typeHints != null) { Part typeHintPart = new StringPart(fieldNames[i] + "@TypeHint", typeHints[i]); partsList.add(typeHintPart); } } final Part[] parts = partsList.toArray(new Part[partsList.size()]); final PostMethod post = new PostMethod(url); post.setFollowRedirects(false); post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); final int expected = 200; final int status = httpClient.executeMethod(post); if(status!=expected) { throw new HttpStatusCodeException(expected, status, "POST", HttpTestBase.getResponseBodyAsStream(post, 0)); } }
/** Upload to an file node structure, see SLING-168 */ public void uploadToFileNode(String url, File localFile, String fieldName, String typeHint) throws IOException { final Part[] parts = new Part[typeHint == null ? 1 : 2]; parts[0] = new FilePart(fieldName, localFile); if (typeHint != null) { parts[1] = new StringPart(fieldName + "@TypeHint", typeHint); } final PostMethod post = new PostMethod(url); post.setFollowRedirects(false); post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); final int status = httpClient.executeMethod(post); final int expected = 200; if(status!=expected) { throw new HttpStatusCodeException(expected, status, "POST", HttpTestBase.getResponseBodyAsStream(post, 0)); } }
method.setFollowRedirects( false ); method.addRequestHeader( "User-Agent", AGENT );
PostMethod method = new PostMethod(path); method.setFollowRedirects(true);
post.setFollowRedirects(false); Body body = doPostCmd.getBody(); if (doPostCmd.getContentType() != null)