本文整理汇总了Java中org.apache.http.message.BasicHeader类的典型用法代码示例。如果您正苦于以下问题:Java BasicHeader类的具体用法?Java BasicHeader怎么用?Java BasicHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicHeader类属于org.apache.http.message包,在下文中一共展示了BasicHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addHttpCookieFromResponseToHeader
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
public void addHttpCookieFromResponseToHeader(final List<Header> headers, final HttpResponse httpResponse) {
String cookieValue = "";
for (Header header : httpResponse.getHeaders("Set-Cookie")) {
List<HttpCookie> httpCookies = HttpCookie.parse(header.getValue());
for (HttpCookie httpCookie : httpCookies) {
if (!cookieValue.isEmpty()) {
cookieValue += "; ";
}
cookieValue += httpCookie.getName() + "=" + httpCookie.getValue();
}
}
headers.add(new BasicHeader("Cookie", cookieValue));
}
示例2: parseCaseInsensitive
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Test public void parseCaseInsensitive() {
long now = System.currentTimeMillis();
Header[] headersArray = new Header[5];
headersArray[0] = new BasicHeader("eTAG", "Yow!");
headersArray[1] = new BasicHeader("DATE", rfc1123Date(now));
headersArray[2] = new BasicHeader("expires", rfc1123Date(now + ONE_HOUR_MILLIS));
headersArray[3] = new BasicHeader("cache-control", "public, max-age=86400");
headersArray[4] = new BasicHeader("content-type", "text/plain");
Map<String, String> headers = BasicNetwork.convertHeaders(headersArray);
NetworkResponse response = new NetworkResponse(0, null, headers, false);
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
assertNotNull(entry);
assertEquals("Yow!", entry.etag);
assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
assertEquals(entry.softTtl, entry.ttl);
assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
}
示例3: isTokenUpToDate
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
static boolean isTokenUpToDate(@NotNull String token) {
if (token.isEmpty()) return false;
final List<BasicHeader> headers = new ArrayList<>();
headers.add(new BasicHeader("Authorization", "Bearer " + token));
headers.add(new BasicHeader("Content-type", EduStepicNames.CONTENT_TYPE_APP_JSON));
CloseableHttpClient httpClient = getBuilder().setDefaultHeaders(headers).build();
try {
final StepicWrappers.AuthorWrapper wrapper =
getFromStepic(EduStepicNames.CURRENT_USER, StepicWrappers.AuthorWrapper.class, httpClient);
if (wrapper != null && !wrapper.users.isEmpty()) {
StepicUser user = wrapper.users.get(0);
return user != null && !user.isGuest();
}
else {
throw new IOException(wrapper == null ? "Got a null current user" : "Got an empty wrapper");
}
}
catch (IOException e) {
LOG.warn(e.getMessage());
return false;
}
}
示例4: afterPropertiesSet
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
public void afterPropertiesSet() throws UnsupportedEncodingException {
Collection<Header> defaultHeaders = new ArrayList<Header>();
Header header = new BasicHeader("Authorization",
"Basic " + BaseEncoding.base64().encode("apollo:".getBytes("UTF-8")));
defaultHeaders.add(header);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("apollo", ""));
CloseableHttpClient httpClient =
HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
.setDefaultHeaders(defaultHeaders).build();
restTemplate = new RestTemplate(httpMessageConverters.getConverters());
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory(httpClient);
requestFactory.setConnectTimeout(portalConfig.connectTimeout());
requestFactory.setReadTimeout(portalConfig.readTimeout());
restTemplate.setRequestFactory(requestFactory);
}
示例5: getHttpClient
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
/**
* Get a valid {@link HttpClient} to use, with a valid token.
*
* @param login
* @return
*/
private CloseableHttpClient getHttpClient(final Boolean login, final HttpUriRequest request)
{
final HttpClientBuilder builder = HttpClientBuilder.create();
String key;
// if (apiClient.getApiToken() == null || apiClient.getApiToken())
if (login)
{
key = apiClient.getApiKey();
}
else
{
key = apiClient.getApiToken();
}
key += ":";
final byte[] credentials = Base64.encodeBase64(key.getBytes(StandardCharsets.UTF_8));
final BasicHeader authHeader = new BasicHeader("Authorization", "Basic " + new String(credentials, StandardCharsets.UTF_8));
request.addHeader(authHeader);
return builder.build();
}
示例6: BasicHeader
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
private Header[] b044Cьь044Cь044C(String str) {
try {
Header[] headerArr = new Header[5];
try {
headerArr[0] = new BasicHeader("content-type", "application/x-amz-json-1.0");
headerArr[1] = new BasicHeader("host", "dynamodb.us-west-2.amazonaws.com");
if (((b0427Ч0427Ч0427Ч + b04270427ЧЧ0427Ч) * b0427Ч0427Ч0427Ч) % bЧЧ0427Ч0427Ч != bЧ0427ЧЧ0427Ч) {
b0427Ч0427Ч0427Ч = 86;
bЧ0427ЧЧ0427Ч = b0427ЧЧЧ0427Ч();
}
headerArr[2] = new BasicHeader("x-amz-date", getYYYYMMDDTHHMMSSZ());
headerArr[3] = new BasicHeader("x-amz-security-token", str);
headerArr[4] = new BasicHeader("x-amz-target", "DynamoDB_20120810.PutItem");
return headerArr;
} catch (Exception e) {
throw e;
}
} catch (Exception e2) {
throw e2;
}
}
示例7: StringBuilder
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
private HttpPost bььь044Cь044C(String str, String str2, HttpPost httpPost) {
try {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("AWS4-HMAC-SHA256 ").append("Credential=").append(str).append("/").append(getYYYYMMDD()).append("/").append(b041B041BЛЛЛ041B).append("/").append(bЛЛ041BЛЛ041B).append("/").append("aws4_request").append(",");
stringBuilder.append("SignedHeaders=").append(new crrcrc().getSignedHeaders(this.b041BЛЛ041BЛ041B)).append(",");
try {
stringBuilder.append("Signature=").append(str2);
String str3 = b041BЛЛЛЛ041B;
StringBuilder stringBuilder2 = new StringBuilder();
String str4 = "POST Authorization String:\n";
if (((b0427Ч0427Ч0427Ч + b04270427ЧЧ0427Ч) * b0427Ч0427Ч0427Ч) % bЧЧ0427Ч0427Ч != bЧ0427ЧЧ0427Ч) {
b0427Ч0427Ч0427Ч = b0427ЧЧЧ0427Ч();
bЧ0427ЧЧ0427Ч = b0427ЧЧЧ0427Ч();
}
Log.d(str3, stringBuilder2.append(str4).append(stringBuilder.toString()).toString());
httpPost.addHeader(new BasicHeader(HttpRequest.HEADER_AUTHORIZATION, stringBuilder.toString()));
return httpPost;
} catch (Exception e) {
throw e;
}
} catch (Exception e2) {
throw e2;
}
}
示例8: get
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
public synchronized String get(Collection<BasicHeader> headers, String url) {
String strResult = null;
HttpGet httpGet = new HttpGet(url);
setHeaders(headers);
L.i("get request url:" + url);
HttpResponse response;
try {
response = mHttpClient.execute(httpGet);
L.i("CustomHttpClient get:" + String.valueOf(response.getStatusLine()));
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
strResult = getContentStr(response.getEntity().getContent());
// L.i("get response string:" + strResult);
}
}catch (Exception e) {
e.printStackTrace();
L.i("get fail");
}
return strResult;
}
示例9: execute
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
protected HttpResponse execute(HttpUriRequest request, boolean consume, String token)
throws ClientProtocolException, IOException
{
if( token != null )
{
final Header tokenHeader = new BasicHeader("X-Authorization", token);
request.setHeader(tokenHeader);
}
request.setHeader("X-Autotest-Key", context.getFullName(""));
HttpResponse response = getClient().execute(request);
if( consume )
{
EntityUtils.consume(response.getEntity());
}
return response;
}
示例10: process
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
if(tokens.isExpired()) {
try {
tokens = this.refresh(tokens);
}
catch(BackgroundException e) {
log.warn(String.format("Failure refreshing OAuth 2 tokens. %s", e.getDetail()));
throw new IOException(e);
}
}
if(StringUtils.isNotBlank(tokens.getAccessToken())) {
if(log.isInfoEnabled()) {
log.info(String.format("Authorizing service request with OAuth2 access token %s", tokens.getAccessToken()));
}
request.removeHeaders(HttpHeaders.AUTHORIZATION);
request.addHeader(new BasicHeader(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", tokens.getAccessToken())));
}
}
示例11: write
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Override
public HttpResponseOutputStream<String> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
final List<Header> headers = new ArrayList<Header>();
if(status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
// Content-Range entity-header is sent with a partial entity-body to specify where
// in the full entity-body the partial body should be applied.
final String header = String.format("bytes %d-%d/%d", range.getStart(), range.getEnd(),
status.getOffset() + status.getLength());
if(log.isDebugEnabled()) {
log.debug(String.format("Add range header %s for file %s", header, file));
}
headers.add(new BasicHeader(HttpHeaders.CONTENT_RANGE, header));
}
if(expect) {
if(status.getLength() > 0L) {
headers.add(new BasicHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE));
}
}
return this.write(file, headers, status);
}
示例12: returnVideoPartAccordingToRange
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Test
public void returnVideoPartAccordingToRange() throws Exception {
byte[] expectedVideo = readVideoFileBytes(Fixtures.videoId);
long min = 1024L * 1024L;
long max = 1024L * 2048L;
Range expectedRange = Range.closed(min, max);
byte[] expectedVideoPart = sliceFile(expectedVideo, expectedRange);
Response response = client.getVideo(Fixtures.videoId, new BasicHeader("Range", format("bytes=%d-%d", min, max)));
assertThat(response.getStatus(), equalTo(206));
byte[] actualVideoPart = response.readEntity(byte[].class);
assertTrue(Arrays.equals(actualVideoPart, expectedVideoPart));
verifyPartialContentHeaders(response, expectedRange, expectedVideo.length);
httpDateFormat.parse(response.getHeaderString("Last-Modified"));
}
示例13: returnVideoPartRespectingEndOfFileForRangeWithoutMaxValue
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Test
public void returnVideoPartRespectingEndOfFileForRangeWithoutMaxValue() throws Exception {
byte[] expectedVideo = readVideoFileBytes(Fixtures.videoId);
long max = expectedVideo.length;
long min = max - 1000L;
Range expectedRange = Range.leftClosed(min, max);
byte[] expectedVideoPart = sliceFile(expectedVideo, expectedRange);
Response response = client.getVideo(Fixtures.videoId, new BasicHeader("Range", format("bytes=%d-", min)));
assertThat(response.getStatus(), equalTo(206));
byte[] actualVideoPart = response.readEntity(byte[].class);
assertTrue(Arrays.equals(actualVideoPart, expectedVideoPart));
verifyPartialContentHeaders(response, expectedRange, expectedVideo.length);
httpDateFormat.parse(response.getHeaderString("Last-Modified"));
}
示例14: returnVideoPartWhenIfModifiedSincePreconditionIsTrue
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Test
public void returnVideoPartWhenIfModifiedSincePreconditionIsTrue() throws Exception {
File video = videoFilePath(Fixtures.videoId).toFile();
String ifModifiedSince = httpDateFormat.format(video.lastModified() - 1);
long min = 1024L * 1024L;
long max = 1024L * 2048L;
Range expectedRange = Range.closed(min, max);
Response response = client.getVideo(Fixtures.videoId,
new BasicHeader("Range", format("bytes=%d-%d", min, max)),
new BasicHeader("If-Modified-Since", ifModifiedSince));
response.close();
assertThat(response.getStatus(), equalTo(206));
verifyPartialContentHeaders(response, expectedRange, video.length());
assertThat(httpDateFormat.parse(response.getHeaderString("Last-Modified")).getTime(), equalTo(video.lastModified()));
}
示例15: returnVideoPartWhenIfRangePreconditionIsTrue
import org.apache.http.message.BasicHeader; //导入依赖的package包/类
@Test
public void returnVideoPartWhenIfRangePreconditionIsTrue() throws Exception {
File video = videoFilePath(Fixtures.videoId).toFile();
String ifRangeLastModified = httpDateFormat.format(video.lastModified());
long min = 1024L * 1024L;
long max = 1024L * 2048L;
Range expectedRange = Range.closed(min, max);
Response response = client.getVideo(Fixtures.videoId,
new BasicHeader("Range", format("bytes=%d-%d", min, max)),
new BasicHeader("If-Range", ifRangeLastModified));
response.close();
assertThat(response.getStatus(), equalTo(206));
verifyPartialContentHeaders(response, expectedRange, video.length());
assertThat(httpDateFormat.parse(response.getHeaderString("Last-Modified")).getTime(),
equalTo(video.lastModified()));
}