本文整理汇总了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();
}
示例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();
}
}
示例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();
}
}
示例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();
}