HttpMessage getHeaders - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for HttpMessage getHeaders method.

This code example shows how to use the following methods:addHeader, getHeaders, getParams
        Assert.assertNull(header1);
    } 
 
    @Test 
    public void testDefaultHeaders() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("custom", "stuff");
        List<Header> defheaders = new ArrayList<Header>();
        defheaders.add(new BasicHeader("custom", "more stuff"));
        request.getParams().setParameter(AllClientPNames.DEFAULT_HEADERS, defheaders);
        HttpContext context = new BasicHttpContext();
 
        HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
        interceptor.process(request, context);
        Header[] headers = request.getHeaders("custom");
        Assert.assertNotNull(headers);
        Assert.assertEquals(2, headers.length);
        Assert.assertEquals("stuff", headers[0].getValue());
        Assert.assertEquals("more stuff", headers[1].getValue());
    } 
6
CodeRank
This code example shows how to use the following methods:getHeaders
      response = httpclient.execute(httpget);
    } catch (Throwable t) {
      throw Throwables.propagate(t);
    } 
 
    Header[] contentTypeHeaders = response.getHeaders("Content-Type");
    assertEquals(1, contentTypeHeaders.length);
    assertTrue(contentTypeHeaders[0].getValue().contains(appcacheMimeType));
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getHeaders
     * @param headerName - the name of the headers to be returned. 
     * @return An array of zero or more headers 
     */ 
    public Header[] getResponseHeaders(String headerName)
    { 
        return response.getHeaders(headerName);
    } 
     
    public String getContentEncoding() {
    	return entity.getContentEncoding().getValue();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getHeaders, getStatusLine
    public static HttpResponseHeaders fromResponse(HttpResponse response, HttpUriRequest request) {
        LogUtils.logd(TAG, "[fromResponse] BEGIN");
 
        HttpResponseHeaders headers = new HttpResponseHeaders();
 
        headers.mResponseCode = response.getStatusLine().getStatusCode();
        headers.mStatusLine = response.getStatusLine().toString();
        headers.mContentEncoding = getResponseHeaderFirstValue(response, HEADER_CONTENT_ENCODING);
        try { 
            headers.mContentLength = Integer.parseInt(
                    getResponseHeaderFirstValue(response, HEADER_CONTENT_LENGTH));
        } catch (NumberFormatException e) {
            headers.mContentLength = -1;
        } 
        headers.mContentType = getResponseHeaderFirstValue(response, HEADER_CONTENT_TYPE);
        headers.mLastModified = getResponseLastModified(response);
        headers.mLastModifiedUtc = getResponseHeaderFirstValue(response, HEADER_LAST_MODIFIED);
        headers.mETag = getResponseHeaderFirstValue(response, HEADER_ETAG);
        headers.mResponse = response;
        headers.mRequest = request;

5
CodeRank
This code example shows how to use the following methods:getHeaders, getParams
        Assert.assertEquals(0, headers2.length);
    } 
 
    @Test 
    public void testAddCookiesUsingExplicitCookieSpec() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.getParams().setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
 
        HttpRoute route = new HttpRoute(this.target, null, false);
 
        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
 
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 

5
CodeRank
This code example shows how to use the following methods:getHeaders, getStatusLine
     */ 
    public Feed createFeed(Feed feed) throws Exception {
        HttpPost request = new HttpPost("http://api.cosm.com/v2/feeds.json");
        request.setEntity(new StringEntity(feed.toJSONObject().toString()));
        HttpResponse response = client.execute(request);			
        StatusLine statusLine = response.getStatusLine();
        request.releaseConnection();
        if ( statusLine.getStatusCode() == 201 ) {
            String arr[] = response.getHeaders("Location")[0].getValue().split("/");
            Integer feedid = Integer.parseInt(arr[arr.length -1]);
            client.getBody(response);
            return this.getFeed(feedid);
        } else { 
            throw new HttpException("No se ha podido crear la fuente " + response.getStatusLine().toString());								
        } 
    } 
 
    /**   
     * Actualiza la fuente indicada en Cosm 
     * 
5
CodeRank
This code example shows how to use the following methods:containsHeader, getHeaders
     * @param response the response 
     * @param header the string chuck 
     * @param message the assert message 
     */ 
    public static void assertHeaderExists(String message, HttpResponse response, String header) {
        assertTrue(message, response.containsHeader(header));
    } 
     
    /** 
     * Checks the response for the containment of the specified header and value. 
     *  
     * @param response the response 
     * @param header the string chuck 
     * @param value the value the header should contain 
     */ 
    public static void assertHeaderContains(HttpResponse response, String header, String value) {
        assertHeaderContains("expected header '" + header + "' with value '" + value + '\'', response, header, value, 0);
    } 
     
    /** 

5
CodeRank
This code example shows how to use the following methods:getHeaders, getStatusLine
            IOException { 
            url = normalizeUrl(url);
            Log.i(LOG_TAG, "Head " + url);
            HttpHead httpGet = new HttpHead(url);
            HttpResponse response = mHttpClient.execute(httpGet);
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new IOException("Unexpected Http status code "
                    + response.getStatusLine().getStatusCode());
            } 
            Header[] clHeaders = response.getHeaders("Content-Length");
            if (clHeaders.length > 0) {
                Header header = clHeaders[0];
                return Long.parseLong(header.getValue());
            } 
            return -1; 
        } 
 
        private String normalizeUrl(String url) throws MalformedURLException {
            return (new URL(new URL(mFileConfigUrl), url)).toString();
        } 
4
CodeRank
This code example shows how to use the following methods:getHeaders
	/** 
	 * @see com.jdroid.java.http.HttpResponseWrapper#getHeader(java.lang.String) 
	 */ 
	@Override 
	public String getHeader(String name) {
		Header[] headerstatusCode = httpResponse.getHeaders(name);
		return headerstatusCode.length > 0 ? headerstatusCode[0].getValue() : null;
	} 
	 
} 
4
CodeRank
This code example shows how to use the following methods:getHeaders
	 
	public static void LogResponse (HttpResponse Response, String Command, Context ctx)
	{ 
		if (BugReporter.Enabled (ctx))
		{ 
			Header [] responses = Response.getHeaders ("Response");
			String responseStr = null;
			if (responses.length > 0) responseStr = responses[0].getValue ();
	 
			if (responseStr != null && responseStr.length () > 0)
			{ 
				BugReporter.addCustomData( Integer.toString(decodecount) , Command + " response: " + responseStr, ctx);
				decodecount++;
			} 
		} 
	} 
	 
	public static HttpResponse ReadSystemConfig (Context ctx) throws Exception
	{ 
		HttpResponse response = HttpClientUtil.SendCommand (String.format ("<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>"));
3
CodeRank

Related HttpMessage getHeaders Questions & Answers:

getHeaders Method Overview
Returns all the headers with a specified name of this message.
See Code Examples for other Android HttpMessage Methods: