當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。