本文整理匯總了Java中org.apache.http.client.methods.HttpHead.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHead.addHeader方法的具體用法?Java HttpHead.addHeader怎麽用?Java HttpHead.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpHead
的用法示例。
在下文中一共展示了HttpHead.addHeader方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testHeadDefaultContentType
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
private void testHeadDefaultContentType(final String mimeType) throws IOException {
final String id = getRandomUniqueId();
createObjectAndClose(id);
addMixin(id, CONTAINER.getURI());
final HttpHead headObjMethod = headObjMethod(id);
String mt = mimeType;
if (mt != null) {
headObjMethod.addHeader("Accept", mt);
} else {
mt = RDFMediaType.TURTLE_WITH_CHARSET;
}
try (final CloseableHttpResponse response = execute(headObjMethod)) {
final Collection<String> contentTypes = getHeader(response, CONTENT_TYPE);
final String contentType = contentTypes.iterator().next();
assertTrue("Didn't find LDP valid content-type header: " + contentType +
"; expected result: " + mt, contentType.contains(mt));
}
}
示例2: testHeadDatastreamWithWantDigest
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
@Test
public void testHeadDatastreamWithWantDigest() throws IOException, ParseException {
final String id = getRandomUniqueId();
createDatastream(id, "x", "01234567890123456789012345678901234567890123456789");
final HttpHead headObjMethod = headObjMethod(id + "/x");
headObjMethod.addHeader(WANT_DIGEST, "SHA");
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(TEXT_PLAIN, response.getFirstHeader(CONTENT_TYPE).getValue());
assertTrue(response.getHeaders(DIGEST).length > 0);
final String digesterHeaderValue = response.getHeaders(DIGEST)[0].getValue();
assertTrue("Fixity Checksum doesn't match",
digesterHeaderValue.equals("sha=9578f951955d37f20b601c26591e260c1e5389bf"));
}
}
示例3: testHeadDatastreamWithWantDigestMultiple
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
@Test
public void testHeadDatastreamWithWantDigestMultiple() throws IOException, ParseException {
final String id = getRandomUniqueId();
createDatastream(id, "x", "01234567890123456789012345678901234567890123456789");
final HttpHead headObjMethod = headObjMethod(id + "/x");
headObjMethod.addHeader(WANT_DIGEST, "SHA, md5;q=0.3");
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(TEXT_PLAIN, response.getFirstHeader(CONTENT_TYPE).getValue());
assertTrue(response.getHeaders(DIGEST).length > 0);
final String digesterHeaderValue = response.getHeaders(DIGEST)[0].getValue();
assertTrue("SHA-1 Fixity Checksum doesn't match",
digesterHeaderValue.indexOf("sha=9578f951955d37f20b601c26591e260c1e5389bf") >= 0);
assertTrue("MD5 fixity checksum doesn't match",
digesterHeaderValue.indexOf("md5=baed005300234f3d1503c50a48ce8e6f") >= 0);
}
}
示例4: testDigestConsistency
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
@Test
public void testDigestConsistency() throws IOException {
final String id = getRandomUniqueId();
executeAndClose(putDSMethod(id, "binary1", "some test content"));
final String headDigestValue;
final HttpHead headObjMethod = headObjMethod(id + "/binary1");
headObjMethod.addHeader(WANT_DIGEST, "sha, md5");
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertTrue(response.getHeaders(DIGEST).length > 0);
headDigestValue = response.getHeaders(DIGEST)[0].getValue();
}
final HttpGet getObjMethod = getObjMethod(id + "/binary1");
getObjMethod.addHeader(WANT_DIGEST, "sha, md5");
try (final CloseableHttpResponse response = execute(getObjMethod)) {
assertTrue(response.getHeaders(DIGEST).length > 0);
assertEquals(headDigestValue, response.getHeaders(DIGEST)[0].getValue());
}
}
示例5: getCsrfToken
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
private String getCsrfToken(CloseableHttpClient client) throws ClientProtocolException, IOException {
String url = getMarketplaceUrl();
HttpHead head = new HttpHead(url + "token");
head.addHeader(X_CSRF_TOKEN, "fetch");
CloseableHttpResponse response = client.execute(head);
EntityUtils.consume(response.getEntity());
String token = null;
Header[] headers = response.getHeaders(X_CSRF_TOKEN);
for (Header header : headers) {
token = header.getValue();
}
return token;
}
示例6: doTestUrlExists
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
private boolean doTestUrlExists(final URI requestUri) {
try {
final HttpHead request = new HttpHead(requestUri);
request.addHeader(new BasicScheme().authenticate(createCredentials(), request, new BasicHttpContext()));
request.setConfig(createRequestConfig());
return httpClient.execute(request).getStatusLine().getStatusCode() == HttpStatus.OK.value();
} catch (final Exception e) {
LOG.error("Exception, message: " + e.getMessage());
}
return false;
}
示例7: testHeadExternalDatastreamWithWantDigest
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
@Test
public void testHeadExternalDatastreamWithWantDigest() throws IOException, ParseException {
final String dsId = getRandomUniqueId();
createDatastream(dsId, "x", "01234567890123456789012345678901234567890123456789");
final String dsUrl = serverAddress + dsId + "/x";
final String externalContentType = "message/external-body;access-type=URL;url=\"" + dsUrl + "\"";
final String id = getRandomUniqueId();
final HttpPut put = putObjMethod(id);
put.addHeader(CONTENT_TYPE, externalContentType);
assertEquals(CREATED.getStatusCode(), getStatus(put));
// Configure HEAD request to NOT follow redirects
final HttpHead headObjMethod = headObjMethod(id);
headObjMethod.addHeader(WANT_DIGEST, "sha");
final RequestConfig.Builder requestConfig = RequestConfig.custom();
requestConfig.setRedirectsEnabled(false);
headObjMethod.setConfig(requestConfig.build());
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(externalContentType, response.getFirstHeader(CONTENT_TYPE).getValue());
assertTrue(response.getHeaders(DIGEST).length > 0);
final String digesterHeaderValue = response.getHeaders(DIGEST)[0].getValue();
assertTrue("Fixity Checksum doesn't match",
digesterHeaderValue.equals("sha=9578f951955d37f20b601c26591e260c1e5389bf"));
}
}
示例8: testHeadExternalDatastreamWithWantDigestMultiple
import org.apache.http.client.methods.HttpHead; //導入方法依賴的package包/類
@Test
public void testHeadExternalDatastreamWithWantDigestMultiple() throws IOException, ParseException {
final String dsId = getRandomUniqueId();
createDatastream(dsId, "x", "01234567890123456789012345678901234567890123456789");
final String dsUrl = serverAddress + dsId + "/x";
final String externalContentType = "message/external-body;access-type=URL;url=\"" + dsUrl + "\"";
final String id = getRandomUniqueId();
final HttpPut put = putObjMethod(id);
put.addHeader(CONTENT_TYPE, externalContentType);
assertEquals(CREATED.getStatusCode(), getStatus(put));
// Configure HEAD request to NOT follow redirects
final HttpHead headObjMethod = headObjMethod(id);
headObjMethod.addHeader(WANT_DIGEST, "sha, md5;q=0.3");
final RequestConfig.Builder requestConfig = RequestConfig.custom();
requestConfig.setRedirectsEnabled(false);
headObjMethod.setConfig(requestConfig.build());
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(externalContentType, response.getFirstHeader(CONTENT_TYPE).getValue());
assertTrue(response.getHeaders(DIGEST).length > 0);
final String digesterHeaderValue = response.getHeaders(DIGEST)[0].getValue();
assertTrue("SHA-1 Fixity Checksum doesn't match",
digesterHeaderValue.indexOf("sha=9578f951955d37f20b601c26591e260c1e5389bf") >= 0);
assertTrue("MD5 fixity checksum doesn't match",
digesterHeaderValue.indexOf("md5=baed005300234f3d1503c50a48ce8e6f") >= 0);
}
}