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


Java GetMethod.getResponseBody方法代码示例

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


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

示例1: getUrlContent

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Retrieves the content under the given URL with username and passwort
 * authentication.
 * 
 * @param url
 *            the URL to read
 * @param username
 * @param password
 * @return the read content.
 * @throws IOException
 *             if an I/O exception occurs.
 */
private static byte[] getUrlContent(URL url, String username,
        String password) throws IOException {
    final HttpClient client = new HttpClient();

    // Set credentials:
    client.getParams().setAuthenticationPreemptive(true);
    final Credentials credentials = new UsernamePasswordCredentials(
            username, password);
    client.getState()
            .setCredentials(
                    new AuthScope(url.getHost(), url.getPort(),
                            AuthScope.ANY_REALM), credentials);

    // Retrieve content:
    final GetMethod method = new GetMethod(url.toString());
    final int status = client.executeMethod(method);
    if (status != HttpStatus.SC_OK) {
        throw new IOException("Error " + status + " while retrieving "
                + url);
    }
    return method.getResponseBody();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:35,代码来源:BasicAuthLoader.java

示例2: testDistinctFile

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testDistinctFile() throws IOException {
    String folderPath = "/UploadFileTest_1_" + System.currentTimeMillis();
    testClient.mkdirs(WEBDAV_BASE_URL, folderPath);
    final String url = HTTP_BASE_URL + folderPath;


    // upload local file
    File localFile = getTestFile();
    testClient.uploadToFileNode(url, localFile, "./file", null);

    // get and check URL of created file
    String urlOfFileNode = url + "/file";

    /*
    TODO: does not work, since no nt:file resource type handler present ???

    final GetMethod get = new GetMethod(urlOfFileNode);
    final int status = httpClient.executeMethod(get);
    assertEquals(urlOfFileNode + " must be accessible after createNode",200,status);

    // compare data with local file (just length)
    final byte[] data = get.getResponseBody();
    assertEquals("size of file must be same", localFile.length(), data.length);
    */

    String webdavUrl = WEBDAV_BASE_URL + folderPath + "/file";
    final GetMethod get = new GetMethod(webdavUrl);
    final int status = httpClient.executeMethod(get);
    assertEquals(urlOfFileNode + " must be accessible after createNode",200,status);

    // compare data with local file (just length)
    final byte[] data = get.getResponseBody();
    assertEquals("size of file must be same", localFile.length(), data.length);

    // download structure
    String json = getContent(urlOfFileNode + ".json", CONTENT_TYPE_JSON);
    // just check for some strings
    assertTrue("checking primary type", json.contains("\"jcr:primaryType\":\"nt:file\""));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:40,代码来源:UploadFileTest.java

示例3: testEmptyBodyAsByteArray

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testEmptyBodyAsByteArray() throws Exception {
    this.server.setHttpService(new EmptyResponseService());
    
    GetMethod httpget = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
        byte[] response = httpget.getResponseBody();
        assertNull(response);
    } finally {
        httpget.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:14,代码来源:TestHttpMethodFundamentals.java

示例4: get

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Send a GET request
 * @param c the cluster definition
 * @param path the path or URI
 * @param headers the HTTP headers to include in the request
 * @return a Response object with response detail
 * @throws IOException
 */
public Response get(Cluster c, String path, Header[] headers) 
    throws IOException {
  GetMethod method = new GetMethod();
  try {
    int code = execute(c, method, headers, path);
    headers = method.getResponseHeaders();
    byte[] body = method.getResponseBody();
    InputStream in = method.getResponseBodyAsStream();
    return new Response(code, headers, body, in);
  } finally {
    method.releaseConnection();
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:Client.java

示例5: getAsByte

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public byte[] getAsByte(String url) throws IOException {
//        clearCookies();
        GetMethod g = new GetMethod(url);
        hc.executeMethod(g);
        return g.getResponseBody();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:7,代码来源:HttpClientUtil.java


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