当前位置: 首页>>代码示例>>Java>>正文


Java PostMethod.getResponseBodyAsString方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.methods.PostMethod.getResponseBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:Java PostMethod.getResponseBodyAsString方法的具体用法?Java PostMethod.getResponseBodyAsString怎么用?Java PostMethod.getResponseBodyAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.methods.PostMethod的用法示例。


在下文中一共展示了PostMethod.getResponseBodyAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: httpClientPost

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public static final String httpClientPost(String url, ArrayList<NameValuePair> list) {
    String result = "";
    HttpClient client = new HttpClient();
    PostMethod postMethod = new PostMethod(url);
    try {
        NameValuePair[] params = new NameValuePair[list.size()];
        for (int i = 0; i < list.size(); i++) {
            params[i] = list.get(i);
        }
        postMethod.addParameters(params);
        client.executeMethod(postMethod);
        result = postMethod.getResponseBodyAsString();
    } catch (Exception e) {
        logger.error("", e);
    } finally {
        postMethod.releaseConnection();
    }
    return result;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:20,代码来源:HttpUtil.java

示例2: httpClientPost

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public static final String httpClientPost(String url, ArrayList<NameValuePair> list) {
	String result = "";
	HttpClient client = new HttpClient();
	PostMethod postMethod = new PostMethod(url);
	try {
		NameValuePair[] params = new NameValuePair[list.size()];
		for (int i = 0; i < list.size(); i++) {
			params[i] = list.get(i);
		}
		postMethod.addParameters(params);
		client.executeMethod(postMethod);
		result = postMethod.getResponseBodyAsString();
	} catch (Exception e) {
		logger.error(e);
	} finally {
		postMethod.releaseConnection();
	}
	return result;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:20,代码来源:HttpUtil.java

示例3: 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

示例4: testPostFilePart

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
 * Test that the body consisting of a file part can be posted.
 */
public void testPostFilePart() throws Exception {
    
    this.server.setHttpService(new EchoService());

    PostMethod method = new PostMethod();
    byte[] content = "Hello".getBytes();
    MultipartRequestEntity entity = new MultipartRequestEntity(
        new Part[] { 
            new FilePart(
                "param1", 
                new ByteArrayPartSource("filename.txt", content), 
                "text/plain", 
                "ISO-8859-1") },
        method.getParams());
    method.setRequestEntity(entity);

    client.executeMethod(method);

    assertEquals(200,method.getStatusCode());
    String body = method.getResponseBodyAsString();
    assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
    assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0);
    assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
    assertTrue(body.indexOf("Hello") >= 0);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestMultipartPost.java

示例5: testPostFilePartUnknownLength

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testPostFilePartUnknownLength() throws Exception {
    
    this.server.setHttpService(new EchoService());

    String enc = "ISO-8859-1";
    PostMethod method = new PostMethod();
    byte[] content = "Hello".getBytes(enc);
    MultipartRequestEntity entity = new MultipartRequestEntity(
        new Part[] { 
            new FilePart(
                "param1", 
                new TestPartSource("filename.txt", content), 
                 "text/plain", 
                 enc) },
         method.getParams());
    method.setRequestEntity(entity);

    client.executeMethod(method);

    assertEquals(200,method.getStatusCode());
    String body = method.getResponseBodyAsString();
    assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
    assertTrue(body.indexOf("Content-Type: text/plain; charset="+enc) >= 0);
    assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
    assertTrue(body.indexOf("Hello") >= 0);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:27,代码来源:TestMultipartPost.java

示例6: testEnclosedEntityNegativeLength

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testEnclosedEntityNegativeLength() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestEntityEnclosingMethod.java

示例7: testEnclosedEntityExplicitLength

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testEnclosedEntityExplicitLength() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, 14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals("This is a test", body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(14, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestEntityEnclosingMethod.java

示例8: testEnclosedEntityChunked

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testEnclosedEntityChunked() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:TestEntityEnclosingMethod.java

示例9: getAccessTokenUserPass

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public String getAccessTokenUserPass() {
    if (!StringUtils.isEmpty(this.oAuth2AccessToken)) {
        return this.oAuth2AccessToken;
    }

    if (StringUtils.isEmpty(this.username) || StringUtils.isEmpty(this.password) && StringUtils.isEmpty(this.oAuth2AuthorizationServer)
            || StringUtils.isEmpty(this.oAuth2ClientId) || StringUtils.isEmpty(this.oAuth2ClientSecret)) {
        return "";
    }

    try {
        HttpClient client = new HttpClient();
        client.getParams().setAuthenticationPreemptive(true);

        // post development
        PostMethod method = new PostMethod(this.getOAuthAuthorizationServer());
        method.setRequestHeader(new Header("Content-type", "application/x-www-form-urlencoded"));

        method.addRequestHeader("Authorization", "Basic " + Base64.encodeBase64String((username + ":" + password).getBytes()));
        NameValuePair[] body = new NameValuePair[] { new NameValuePair("username", username), new NameValuePair("password", password),
                new NameValuePair("client_id", oAuth2ClientId), new NameValuePair("client_secret", oAuth2ClientSecret),
                new NameValuePair("grant_type", oAuth2GrantType) };
        method.setRequestBody(body);
        int responseCode = client.executeMethod(method);

        String responseBody = method.getResponseBodyAsString();
        if (responseCode != 200) {
            throw new RuntimeException("Failed to fetch access token form authorization server, " + this.getOAuthAuthorizationServer()
                    + ", got response code " + responseCode);
        }

        JSONObject accessResponse = new JSONObject(responseBody);
        accessResponse.getString("access_token");
        return (this.oAuth2AccessToken = accessResponse.getString("access_token"));
    } catch (Exception e) {
        throw new RuntimeException("Failed to read response from authorizationServer at " + this.getOAuthAuthorizationServer(), e);
    }
}
 
开发者ID:wso2-incubator,项目名称:scim2-compliance-test-suite,代码行数:39,代码来源:CSP.java

示例10: post

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public String post(String postURL, Map<String, String> partam, String cookies)
            throws IOException {
//        clearCookies();
        PostMethod p = new PostMethod(postURL);
        for (String key : partam.keySet()) {
            if (partam.get(key) != null) {
                p.setParameter(key, partam.get(key));
            }
        }
        if (StringUtils.isNotEmpty(cookies)) {
            p.addRequestHeader("cookie", cookies);
        }
        hc.executeMethod(p);
        return p.getResponseBodyAsString();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:16,代码来源:HttpClientUtil.java

示例11: getAccessToken

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public String getAccessToken() {
    if (this.oAuth2AccessToken != null) {
        return this.oAuth2AccessToken;
    }

    try {
        HttpClient client = new HttpClient();
        client.getParams().setAuthenticationPreemptive(true);
        Credentials defaultcreds = new UsernamePasswordCredentials(this.getUsername(), this.getPassword());
        client.getState().setCredentials(AuthScope.ANY, defaultcreds);

        PostMethod method = new PostMethod(this.getOAuthAuthorizationServer());
        method.setRequestBody("grant_type=client_credentials");
        int responseCode = client.executeMethod(method);
        if (responseCode != 200) {

            throw new RuntimeException("Failed to fetch access token form authorization server, " + this.getOAuthAuthorizationServer()
                    + ", got response code " + responseCode);
        }
        String responseBody = method.getResponseBodyAsString();
        JSONObject accessResponse = new JSONObject(responseBody);
        accessResponse.getString("access_token");
        return (this.oAuth2AccessToken = accessResponse.getString("access_token"));
    } catch (Exception e) {
        throw new RuntimeException("Failed to read response from authorizationServer at " + this.getOAuthAuthorizationServer(), e);
    }
}
 
开发者ID:wso2-incubator,项目名称:scim2-compliance-test-suite,代码行数:29,代码来源:CSP.java

示例12: testPostWithSelector

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testPostWithSelector() throws Exception {
    final PostMethod post = new PostMethod(testNodeRT.nodeUrl + ".TEST_SEL_2.txt");
    final int status = httpClient.executeMethod(post);
    assertEquals("POST to testNodeRT should return 200", 200, status);
    final String content = post.getResponseBodyAsString();
    assertServlet(content, SEL_SERVLET_SUFFIX);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:8,代码来源:SelectorServletTest.java

示例13: testPostMethodExistingResource

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testPostMethodExistingResource() throws Exception {
    final PostMethod post = new PostMethod(testNodeNORT.nodeUrl + TEST_URL_SUFFIX);
    final int status = httpClient.executeMethod(post);
    assertEquals("PUT should return 200", 200, status);
    final String content = post.getResponseBodyAsString();
    assertServlet(content, REQUEST_URI_OPTING_SERVLET_SUFFIX);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:8,代码来源:RequestUriOptingServletTest.java

示例14: testPuttMethodNonExistingResource

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testPuttMethodNonExistingResource() throws Exception {
    final PostMethod post = new PostMethod(NONEXISTING_RESOURCE_URL + TEST_URL_SUFFIX);
    final int status = httpClient.executeMethod(post);
    assertEquals("PUT should return 200", 200, status);
    final String content = post.getResponseBodyAsString();
    assertServlet(content, REQUEST_URI_OPTING_SERVLET_SUFFIX);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:8,代码来源:RequestUriOptingServletTest.java

示例15: testEnclosedEntityRepeatable

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testEnclosedEntityRepeatable() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);

    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new EchoService()));
    this.server.setRequestHandler(handlerchain);
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(input.length, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:32,代码来源:TestEntityEnclosingMethod.java


注:本文中的org.apache.commons.httpclient.methods.PostMethod.getResponseBodyAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。