Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a code excerpt we're using in our app to set request headers. You'll note we set the CONTENT_TYPE header only on a POST or PUT, but the general method of adding headers (via a request interceptor) is used for GET as well.</p> <pre><code>/** * HTTP request types */ public static final int POST_TYPE = 1; public static final int GET_TYPE = 2; public static final int PUT_TYPE = 3; public static final int DELETE_TYPE = 4; /** * HTTP request header constants */ public static final String CONTENT_TYPE = "Content-Type"; public static final String ACCEPT_ENCODING = "Accept-Encoding"; public static final String CONTENT_ENCODING = "Content-Encoding"; public static final String ENCODING_GZIP = "gzip"; public static final String MIME_FORM_ENCODED = "application/x-www-form-urlencoded"; public static final String MIME_TEXT_PLAIN = "text/plain"; private InputStream performRequest(final String contentType, final String url, final String user, final String pass, final Map&lt;String, String&gt; headers, final Map&lt;String, String&gt; params, final int requestType) throws IOException { DefaultHttpClient client = HTTPClientFactory.newClient(); client.getParams().setParameter(HttpProtocolParams.USER_AGENT, mUserAgent); // add user and pass to client credentials if present if ((user != null) &amp;&amp; (pass != null)) { client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass)); } // process headers using request interceptor final Map&lt;String, String&gt; sendHeaders = new HashMap&lt;String, String&gt;(); if ((headers != null) &amp;&amp; (headers.size() &gt; 0)) { sendHeaders.putAll(headers); } if (requestType == HTTPRequestHelper.POST_TYPE || requestType == HTTPRequestHelper.PUT_TYPE ) { sendHeaders.put(HTTPRequestHelper.CONTENT_TYPE, contentType); } // request gzip encoding for response sendHeaders.put(HTTPRequestHelper.ACCEPT_ENCODING, HTTPRequestHelper.ENCODING_GZIP); if (sendHeaders.size() &gt; 0) { client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { for (String key : sendHeaders.keySet()) { if (!request.containsHeader(key)) { request.addHeader(key, sendHeaders.get(key)); } } } }); } //.... code omitted ....// } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload