本文整理匯總了Java中org.apache.commons.httpclient.methods.PostMethod.setFollowRedirects方法的典型用法代碼示例。如果您正苦於以下問題:Java PostMethod.setFollowRedirects方法的具體用法?Java PostMethod.setFollowRedirects怎麽用?Java PostMethod.setFollowRedirects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.methods.PostMethod
的用法示例。
在下文中一共展示了PostMethod.setFollowRedirects方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processorsActive
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
@Test
public void processorsActive() throws HttpException, IOException {
final PostMethod post = new PostMethod(testUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX);
post.setFollowRedirects(false);
post.setParameter("DummyModification", "true");
try {
T.getHttpClient().executeMethod(post);
final String content = post.getResponseBodyAsString();
final int i1 = content.indexOf("source:SlingPostProcessorOne");
assertTrue("Expecting first processor to be present", i1 > 0);
final int i2 = content.indexOf("source:SlingPostProcessorTwo");
assertTrue("Expecting second processor to be present", i2 > 0);
assertTrue("Expecting service ranking to put processor one first", i1 < i2);
} finally {
post.releaseConnection();
}
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:21,代碼來源:SlingPostProcessorTest.java
示例2: simplePost
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
private void simplePost(String url, String statusParam, int expectStatus,
String expectLocation) throws IOException {
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
if (statusParam != null) {
post.addParameter(SlingPostConstants.RP_STATUS, statusParam);
}
final int status = httpClient.executeMethod(post);
assertEquals("Unexpected status response", expectStatus, status);
if (expectLocation != null) {
String location = post.getResponseHeader("Location").getValue();
assertNotNull("Expected location header", location);
assertTrue(location.endsWith(expectLocation));
}
post.releaseConnection();
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:23,代碼來源:PostStatusTest.java
示例3: runTest
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
private void runTest(String acceptHeaderValue, boolean useHttpEquiv, String expectedContentType) throws Exception {
final String info = (useHttpEquiv ? "Using http-equiv parameter" : "Using Accept header") + ": ";
final String url = HTTP_BASE_URL + MY_TEST_PATH;
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
if(acceptHeaderValue != null) {
if(useHttpEquiv) {
post.addParameter(":http-equiv-accept", acceptHeaderValue);
} else {
post.addRequestHeader("Accept", acceptHeaderValue);
}
}
final int status = httpClient.executeMethod(post) / 100;
assertEquals(info + "Expected status 20x for POST at " + url, 2, status);
final Header h = post.getResponseHeader("Content-Type");
assertNotNull(info + "Expected Content-Type header", h);
final String ct = h.getValue();
assertTrue(info + "Expected Content-Type '" + expectedContentType + "' for Accept header=" + acceptHeaderValue
+ " but got '" + ct + "'",
ct.startsWith(expectedContentType));
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:24,代碼來源:PostServletOutputContentTypeTest.java
示例4: testJsonContentTypeException
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testJsonContentTypeException() throws Exception {
// Perform a POST that fails: invalid PostServlet operation
// with Accept header set to JSON
final String url = HTTP_BASE_URL + MY_TEST_PATH;
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
post.addParameter(new NameValuePair(
SlingPostConstants.RP_OPERATION,
"InvalidTestOperationFor" + getClass().getSimpleName()));
post.addRequestHeader("Accept", CONTENT_TYPE_JSON);
final int status = httpClient.executeMethod(post);
assertEquals(500, status);
final String contentType = post.getResponseHeader("Content-Type").getValue();
final String expected = CONTENT_TYPE_JSON;
assertTrue("Expecting content-type " + expected + " for failed POST request, got " + contentType,
contentType!=null && contentType.startsWith(expected));
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:20,代碼來源:PostServletOutputContentTypeTest.java
示例5: testRecentRequestsEscape
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testRecentRequestsEscape() throws Exception {
final String basePath = "/" + getClass().getSimpleName() + "/" + Math.random();
final String path = basePath + ".html/%22%3e%3cscript%3ealert(29679)%3c/script%3e";
// POST to create node
{
final PostMethod post = new PostMethod(HTTP_BASE_URL + path);
post.setFollowRedirects(false);
final int status = httpClient.executeMethod(post);
assertEquals(201, status);
}
// And check that recent requests output does not contain <script>
{
final String content = getContent(HTTP_BASE_URL + "/system/console/requests?index=1", CONTENT_TYPE_HTML);
final String scriptTag = "<script>";
assertFalse("Content should not contain '" + scriptTag + "'", content.contains(scriptTag));
}
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:20,代碼來源:SLING2085Test.java
示例6: assertPostStatus
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
protected HttpMethod assertPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams,
List<Header> headers, String assertMessage) throws IOException {
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
if (headers != null) {
for (Header header : headers) {
post.addRequestHeader(header);
}
}
if (postParams != null) {
final NameValuePair[] nvp = {};
post.setRequestBody(postParams.toArray(nvp));
}
final int status = H.getHttpClient().executeMethod(post);
if (assertMessage == null) {
assertEquals(expectedStatusCode, status);
} else {
assertEquals(assertMessage, expectedStatusCode, status);
}
return post;
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:25,代碼來源:AuthenticationResponseCodeTest.java
示例7: assertAuthenticatedPostStatus
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/** Execute a POST request and check status */
public void assertAuthenticatedPostStatus(Credentials creds, String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage)
throws IOException {
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
URL baseUrl = new URL(HTTP_BASE_URL);
AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
post.setDoAuthentication(true);
Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
try {
httpClient.getState().setCredentials(authScope, creds);
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);
}
} finally {
httpClient.getState().setCredentials(authScope, oldCredentials);
}
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:29,代碼來源:AuthenticatedTestUtil.java
示例8: testCustomPostResponseCreator
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testCustomPostResponseCreator() throws Exception {
final PostMethod post = new PostMethod(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX);
post.addParameter(":responseType", "custom");
post.setFollowRedirects(false);
final int status = httpClient.executeMethod(post);
assertEquals("Unexpected status response", 201, status);
assertEquals("Thanks!", post.getResponseBodyAsString());
post.releaseConnection();
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:14,代碼來源:PostResponseCreatorTest.java