本文整理了Java中org.apache.http.Header.getElements()
方法的一些代码示例,展示了Header.getElements()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.getElements()
方法的具体详情如下:
包路径:org.apache.http.Header
类名称:Header
方法名:getElements
[英]Parses the value.
[中]解析值。
代码示例来源:origin: robovm/robovm
public List<Cookie> parse(final Header header, final CookieOrigin origin)
throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
HeaderElement[] elems = header.getElements();
return parse(elems, origin);
}
代码示例来源:origin: rest-assured/rest-assured
protected boolean hasEncoding( final HttpResponse response, final String encoding ) {
HttpEntity entity = response.getEntity();
if ( entity == null ) return false;
Header ceHeader = entity.getContentEncoding();
if ( ceHeader == null ) return false;
HeaderElement[] codecs = ceHeader.getElements();
for ( int i = 0; i < codecs.length; i++ )
if ( encoding.equalsIgnoreCase( codecs[i].getName() ) )
return true;
return false;
}
}
代码示例来源:origin: robovm/robovm
public static String getContentCharSet(final HttpEntity entity)
throws ParseException {
if (entity == null) {
throw new IllegalArgumentException("HTTP entity may not be null");
}
String charset = null;
if (entity.getContentType() != null) {
HeaderElement values[] = entity.getContentType().getElements();
if (values.length > 0) {
NameValuePair param = values[0].getParameterByName("charset");
if (param != null) {
charset = param.getValue();
}
}
}
return charset;
}
代码示例来源:origin: alibaba/nacos
public static HttpResult httpPostLarge(String url, Map<String, String> headers, String content) {
try {
HttpClientBuilder builder = HttpClients.custom();
builder.setUserAgent(UtilsAndCommons.SERVER_VERSION);
builder.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
CloseableHttpClient httpClient = builder.build();
HttpPost httpost = new HttpPost(url);
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpost.setHeader(entry.getKey(), entry.getValue());
}
httpost.setEntity(new StringEntity(content, ContentType.create("application/json", "UTF-8")));
HttpResponse response = httpClient.execute(httpost);
HttpEntity entity = response.getEntity();
HeaderElement[] headerElements = entity.getContentType().getElements();
String charset = headerElements[0].getParameterByName("charset").getValue();
return new HttpResult(response.getStatusLine().getStatusCode(),
IOUtils.toString(entity.getContent(), charset), Collections.<String, String>emptyMap());
} catch (Exception e) {
return new HttpResult(500, e.toString(), Collections.<String, String>emptyMap());
}
}
代码示例来源:origin: alibaba/nacos
public static HttpResult httpPost(String url, List<String> headers, Map<String, String> paramValues, String encoding) {
try {
HttpPost httpost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(5000).setConnectTimeout(5000).setSocketTimeout(5000).setRedirectsEnabled(true).setMaxRedirects(5).build();
httpost.setConfig(requestConfig);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> entry : paramValues.entrySet()) {
nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
httpost.setEntity(new UrlEncodedFormEntity(nvps, encoding));
HttpResponse response = postClient.execute(httpost);
HttpEntity entity = response.getEntity();
String charset = encoding;
if (entity.getContentType() != null) {
HeaderElement[] headerElements = entity.getContentType().getElements();
if (headerElements != null && headerElements.length > 0 && headerElements[0] != null &&
headerElements[0].getParameterByName("charset") != null) {
charset = headerElements[0].getParameterByName("charset").getValue();
}
}
return new HttpResult(response.getStatusLine().getStatusCode(), IOUtils.toString(entity.getContent(), charset), Collections.<String, String>emptyMap());
} catch (Throwable e) {
return new HttpResult(500, e.toString(), Collections.<String, String>emptyMap());
}
}
代码示例来源:origin: apache/geode
private String getCookieHeader(CloseableHttpResponse resp) {
Header lastHeader = resp.getLastHeader("Set-Cookie");
if (lastHeader == null) {
return null;
}
return lastHeader.getElements()[0].getValue();
}
代码示例来源:origin: robovm/robovm
public Set<String> getAllowedMethods(final HttpResponse response) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderIterator it = response.headerIterator("Allow");
Set<String> methods = new HashSet<String>();
while (it.hasNext()) {
Header header = it.nextHeader();
HeaderElement[] elements = header.getElements();
for (HeaderElement element : elements) {
methods.add(element.getName());
}
}
return methods;
}
代码示例来源:origin: mttkay/ignition
@Override
public void process(final HttpResponse response, final HttpContext context) {
// Inflate any responses compressed with gzip
final HttpEntity entity = response.getEntity();
if (entity != null) {
final Header encoding = entity.getContentEncoding();
if (encoding != null) {
for (HeaderElement element : encoding.getElements()) {
if (element.getName().equalsIgnoreCase(IgnitedHttp.ENCODING_GZIP)) {
response.setEntity(new GzipInflatingEntity(response.getEntity()));
break;
}
}
}
}
}
代码示例来源:origin: robovm/robovm
HeaderElement[] elems = header.getElements();
代码示例来源:origin: robovm/robovm
elems = header.getElements();
代码示例来源:origin: internetarchive/heritrix3
unsatisfiableCharset = response.getFirstHeader("content-type").getElements()[0].getParameterByName("charset").getValue();
} catch (Exception f) {
unsatisfiableCharset = "<failed-to-parse>";
代码示例来源:origin: robovm/robovm
HeaderElement[] encodings = null;
try {
encodings = transferEncodingHeader.getElements();
} catch (ParseException px) {
throw new ProtocolException
代码示例来源:origin: confluentinc/ksql
@Test
public void testHandle() throws IOException {
final HttpResponse response = mock(HttpResponse.class);
final StatusLine statusLine = mock(StatusLine.class);
final HttpEntity entity = mock(HttpEntity.class);
final Logger log = mock(Logger.class);
final Header header = mock(Header.class);
expect(response.getStatusLine()).andReturn(statusLine).once();
expect(statusLine.getStatusCode()).andReturn(HttpStatus.SC_OK).once();
expect(response.getEntity()).andReturn(entity).times(2);
final ByteArrayInputStream bais = new ByteArrayInputStream("yolo".getBytes(StandardCharsets.UTF_8));
expect(entity.getContent()).andReturn(bais).times(2);
expect(entity.getContentType()).andReturn(header).times(1);
expect(header.getElements()).andReturn(new HeaderElement[]{});
expect(entity.getContentLength()).andReturn(4L).times(2);
log.warn("yolo");
expectLastCall().once();
replay(response, statusLine, entity, header, log);
final KsqlVersionCheckerResponseHandler kvcr = new KsqlVersionCheckerResponseHandler(log);
kvcr.handle(response);
verify(response, statusLine, entity, header, log);
}
}
代码示例来源:origin: robovm/robovm
throw new IllegalArgumentException("Cookie origin may not be null");
HeaderElement[] helems = header.getElements();
boolean versioned = false;
boolean netscape = false;
代码示例来源:origin: com.jayway.restassured/rest-assured
protected boolean hasEncoding( final HttpResponse response, final String encoding ) {
HttpEntity entity = response.getEntity();
if ( entity == null ) return false;
Header ceHeader = entity.getContentEncoding();
if ( ceHeader == null ) return false;
HeaderElement[] codecs = ceHeader.getElements();
for ( int i = 0; i < codecs.length; i++ )
if ( encoding.equalsIgnoreCase( codecs[i].getName() ) )
return true;
return false;
}
}
代码示例来源:origin: jamesagnew/hapi-fhir
@Override
public Reader createReader() throws IOException {
HttpEntity entity = myResponse.getEntity();
if (entity == null) {
return new StringReader("");
}
Charset charset = null;
if (entity.getContentType() != null && entity.getContentType().getElements() != null
&& entity.getContentType().getElements().length > 0) {
ContentType ct = ContentType.get(entity);
charset = ct.getCharset();
}
if (charset == null) {
if (Constants.STATUS_HTTP_204_NO_CONTENT != myResponse.getStatusLine().getStatusCode()) {
ourLog.debug("Response did not specify a charset, defaulting to utf-8");
}
charset = Charset.forName("UTF-8");
}
return new InputStreamReader(readEntity(), charset);
}
代码示例来源:origin: stackoverflow.com
httpclient.addResponseInterceptor(new HttpResponseInterceptor() {
public void process(
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
HttpEntity entity = response.getEntity();
Header ceheader = entity.getContentEncoding();
if (ceheader != null) {
HeaderElement[] codecs = ceheader.getElements();
for (int i = 0; i < codecs.length; i++) {
if (codecs[i].getName().equalsIgnoreCase("gzip")) {
response.setEntity(
new GzipDecompressingEntity(response.getEntity()));
return;
}
}
}
}
});
代码示例来源:origin: stackoverflow.com
mHttpClient.addResponseInterceptor(new HttpResponseInterceptor() {
public void process(final HttpResponse response,
final HttpContext context) throws HttpException,
IOException {
HttpEntity entity = response.getEntity();
Header encheader = entity.getContentEncoding();
if (encheader != null) {
HeaderElement[] codecs = encheader.getElements();
for (int i = 0; i < codecs.length; i++) {
if (codecs[i].getName().equalsIgnoreCase("gzip")) {
response.setEntity(new GzipDecompressingEntity(
entity));
return;
}
}
}
}
});
代码示例来源:origin: sd4324530/fastweixin
private void downloadVideo(DownloadMaterialResponse response){
String url = response.getDownUrl();
LOG.debug("Download url: " + url);
RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(NetWorkCenter.CONNECT_TIMEOUT).setConnectTimeout(NetWorkCenter.CONNECT_TIMEOUT).setSocketTimeout(NetWorkCenter.CONNECT_TIMEOUT).build();
CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
HttpGet get = new HttpGet(url);
try {
CloseableHttpResponse r = client.execute(get);
if (HttpStatus.SC_OK == r.getStatusLine().getStatusCode()) {
InputStream inputStream = r.getEntity().getContent();
Header[] headers = r.getHeaders("Content-disposition");
Header length = r.getHeaders("Content-Length")[0];
response.setContent(inputStream, Integer.valueOf(length.getValue()));
response.setFileName(headers[0].getElements()[0].getParameterByName("filename").getValue());
}
} catch (IOException e){
LOG.error("IO异常处理", e);
} catch (Exception e) {
LOG.error("其他异常", e);
}
}
代码示例来源:origin: magro/memcached-session-manager
public static String getSessionIdFromResponse( final HttpResponse response ) {
final Header cookie = response.getFirstHeader( "Set-Cookie" );
if ( cookie != null ) {
for ( final HeaderElement header : cookie.getElements() ) {
if ( "JSESSIONID".equals( header.getName() ) ) {
return header.getValue();
}
}
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!