Example usage for com.google.common.net HttpHeaders ACCEPT_CHARSET

List of usage examples for com.google.common.net HttpHeaders ACCEPT_CHARSET

Introduction

In this page you can find the example usage for com.google.common.net HttpHeaders ACCEPT_CHARSET.

Prototype

String ACCEPT_CHARSET

To view the source code for com.google.common.net HttpHeaders ACCEPT_CHARSET.

Click Source Link

Document

The HTTP Accept-Charset header field name.

Usage

From source file:jp.tomorrowkey.irkit4j.http.HttpClient.java

@VisibleForTesting
HttpURLConnection newHttpURLConnection(URL url, HttpRequestMethod method, String encoding) throws IOException {
    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
    httpURLConnection.setDoInput(true);//from   ww  w.j av  a2s .co  m
    httpURLConnection.setDoOutput(method == HttpRequestMethod.POST);
    httpURLConnection.setUseCaches(false);
    httpURLConnection.setRequestMethod(method.toString());
    httpURLConnection.setRequestProperty(HttpHeaders.ACCEPT_CHARSET, encoding);
    if (method == HttpRequestMethod.POST) {
        httpURLConnection.setRequestProperty(HttpHeaders.CONTENT_TYPE,
                "application/x-www-form-urlencoded;charset=" + encoding);
    }
    return httpURLConnection;
}

From source file:org.hashes.CollisionInjector.java

protected void addRequestHeaders(final int contentLength, final StringBuilder payloadBuilder) {

    // http://www.ietf.org/rfc/rfc2616.txt
    // Each header field consists of a name followed by a colon (":") and the field value. Field names are
    // case-insensitive.
    final Locale locale = Locale.ENGLISH;
    final Map<String, String> defaultHeaders = new LinkedHashMap<String, String>();
    defaultHeaders.put(HttpHeaders.HOST.toLowerCase(locale), this.configuration.getTarget().getHost());
    defaultHeaders.put(HttpHeaders.CONTENT_TYPE.toLowerCase(locale), "application/x-www-form-urlencoded");
    defaultHeaders.put(HttpHeaders.ACCEPT_CHARSET.toLowerCase(locale), this.configuration.getCharset().name());
    defaultHeaders.put(HttpHeaders.CONTENT_LENGTH.toLowerCase(locale), String.valueOf(contentLength));
    defaultHeaders.put(HttpHeaders.USER_AGENT.toLowerCase(locale), "hashes");
    defaultHeaders.put(HttpHeaders.ACCEPT.toLowerCase(locale), "*/*");

    for (final Entry<String, String> externalHeaders : this.configuration.getHeaders().entrySet()) {
        defaultHeaders.put(externalHeaders.getKey().toLowerCase(locale), externalHeaders.getValue());
    }//w  w w  .j  av  a  2  s . c  o  m

    for (final Entry<String, String> header : defaultHeaders.entrySet()) {
        payloadBuilder.append(header.getKey());
        payloadBuilder.append(": ");
        payloadBuilder.append(header.getValue());
        payloadBuilder.append("\r\n");
    }

    payloadBuilder.append("\r\n");
}