本文整理汇总了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