Android HttpMessage - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:addHeader, getParams
        if (DEBUG) Log.d(TAG, "Downloading XTRA data from " + url);
 
        AndroidHttpClient client = null;
        try { 
            client = AndroidHttpClient.newInstance("Android");
            HttpUriRequest req = new HttpGet(url);
 
            if (isProxySet) {
                HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
            } 
 
            req.addHeader(
                    "Accept", 
                    "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); 
 
            req.addHeader(
                    "x-wap-profile", 
                    "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); 
 

8
CodeRank
This code example shows how to use the following methods:containsHeader, getAllHeaders
        } 
    } 
 
    private static void checkResponseForHeader(HttpResponse response, String headerName) {
        Assert.assertTrue("response doesn't contain header '" + headerName + "', all response headers=" +
                showHeaders(response.getAllHeaders()), response.containsHeader(headerName));
    } 
 
    private static String showHeaders(final org.apache.http.Header[] headers) {
        StringBuilder stringBuilder = new StringBuilder();
        try (Formatter result = new Formatter(stringBuilder)) {
            for (Header header : headers) {
                result.format("{name=%s, value=%s}, ", header.getName(), header.getValue());
            } 
            return result.toString();
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:addHeader, getParams
        if (DEBUG) Log.d(TAG, "Downloading XTRA data from " + url);
 
        AndroidHttpClient client = null;
        try { 
            client = AndroidHttpClient.newInstance("Android");
            HttpUriRequest req = new HttpGet(url);
 
            if (isProxySet) {
                HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
            } 
 
            req.addHeader(
                    "Accept", 
                    "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); 
 
            req.addHeader(
                    "x-wap-profile", 
                    "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); 
 

7
CodeRank
This code example shows how to use the following methods:getFirstHeader, getEntity, getStatusLine
        throws JSONException, InvalidRequestException, 
               InvalidClientException, InvalidGrantException, 
               UnauthorizedClientException, UnsupportedGrantTypeException, 
               InvalidScopeException, OAuthException { 
 
        StatusLine statusLine = this.httpResponse.getStatusLine();
        this.statusCode = statusLine.getStatusCode();
        try { 
            getStringEntity(); 
        } catch (IOException ex) {
            Logger.getLogger(Response.class.getName()).log(Level.SEVERE, null, ex);
        } 
 
        if (parseStringEntityForJson()) { 
            JsonParser.parseForErrors(jsonResponse);
        } else if (parseStringEntityForParameters()) { 
        } 
 
        switch (statusCode) {
            case (200): { 

7
CodeRank
This code example shows how to use the following methods:addHeader
    @Test 
    public void testEntityWithMultipleContentLengthSomeWrong() throws Exception { 
        final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
        final HttpMessage message = new DummyHttpMessage();
 
        message.addHeader("Content-Type", "unknown");
        message.addHeader("Content-Length", "1");
        message.addHeader("Content-Length", "yyy");
        message.addHeader("Content-Length", "xxx");
        Assert.assertEquals(1, lenStrategy.determineLength(message));
    } 
 
    @Test 
    public void testEntityWithMultipleContentLengthAllWrong() throws Exception { 
        final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
        final HttpMessage message = new DummyHttpMessage();
 
        message.addHeader("Content-Type", "unknown");
        message.addHeader("Content-Length", "yyy");
        message.addHeader("Content-Length", "xxx");
7
CodeRank
This code example shows how to use the following methods:addHeader, addHeader
	} 
 
	void addHeaders(HttpPost post) {
		checkState(); 
 
		post.addHeader("Host", "play.google.com");
		post.addHeader("Connection", "keep-alive");
		post.addHeader("Content-Type", "application/json; charset=utf-8");
		// XXX get this dynamically by fetching and executing the nocache.js file:  
		// https://play.google.com/apps/publish/v2/gwt/com.google.wireless.android.vending.developer.fox.Fox.nocache.js 
		post.addHeader("X-GWT-Permutation", "EC203CA4CDFF1F0285B065B554E0D784");
		post.addHeader("Origin", "https://play.google.com");
		post.addHeader("X-GWT-Module-Base", "https://play.google.com/apps/publish/v2/gwt/");
		post.addHeader("Referer", "https://play.google.com/apps/publish/v2/?dev_acc="
				+ getSessionCredentials().getDeveloperAccountId()); 
	} 
 
	String createDeveloperUrl(String baseUrl) {
		checkState(); 
 
8
CodeRank
This code example shows how to use the following methods:addHeader
 
 
    // Private stuff 
    protected void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, AsyncHttpResponseHandler responseHandler, Context context) {
        if(contentType != null) {
            uriRequest.addHeader("Content-Type", contentType);
        } 
 
        Future<?> request = threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler));
 
        if(context != null) {
            // Add request to request map 
            List<WeakReference<Future<?>>> requestList = requestMap.get(context);
            if(requestList == null) {
                requestList = new LinkedList<WeakReference<Future<?>>>();
                requestMap.put(context, requestList);
            } 
 
            requestList.add(new WeakReference<Future<?>>(request));
 
7
CodeRank
This code example shows how to use the following methods:containsHeader, getFirstHeader, getStatusLine
  } 
 
  private static void playerInactiveErrorCheck(HttpResponse resp)
    throws PlayerInactiveException 
  { 
    if(resp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND
      && resp.containsHeader(MISSING_RESOURCE_HEADER)
      && resp.getFirstHeader(MISSING_RESOURCE_HEADER).getValue().equals("player")
      && resp.containsHeader(MISSING_RESOURCE_REASON_HEADER)
      && resp.getFirstHeader(MISSING_RESOURCE_REASON_HEADER).getValue().equals("inactive"))
    { 
        throw new PlayerInactiveException(); 
    } 
  } 
 
  private static void noLongerInPlayerErrorCheck(HttpResponse resp)
    throws NoLongerInPlayerException 
  { 
    if(resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
      && resp.containsHeader(WWW_AUTH_HEADER)
6
CodeRank
This code example shows how to use the following methods:setHeader, setEntity
        String errorJson = "{\"ok\" : false,\"operation_id\" : \"OpID\"," +
                "\"error\" : \"Could not parse request body\"," + 
                "\"error_code\" : 40000," + 
                "\"details\" : {\"error\" : \"Unexpected token '#'\"," + 
                "\"location\" : {\"line\" : 10,\"column\" : 3}}}"; 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 400, "Bad Request"));
        InputStreamEntity inputStreamEntity = new InputStreamEntity(
                new ByteArrayInputStream(errorJson.getBytes()),
                errorJson.getBytes().length);
        httpResponse.setEntity(inputStreamEntity);
        httpResponse.setHeader(new BasicHeader(CONTENT_TYPE_KEY,
                                               UA_JSON_RESPONSE));
 
        ScheduleAPIResponseHandler handler = new ScheduleAPIResponseHandler();
 
        try{ 
            handler.handleResponse(httpResponse);
        } 
        catch (APIRequestException ex){

6
CodeRank
This code example shows how to use the following methods:addHeader, getParams
        if (Config.LOGD) Log.d(TAG, "Downloading XTRA data from " + url);
 
        AndroidHttpClient client = null;
        try { 
            client = AndroidHttpClient.newInstance("Android");
            HttpUriRequest req = new HttpGet(url);
 
            if (isProxySet) {
                HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
            } 
 
            req.addHeader(
                    "Accept", 
                    "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); 
 
            req.addHeader(
                    "x-wap-profile", 
                    "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); 
 

6
CodeRank

Related Android HttpMessage Questions & Answers:

See Code Examples for Android HttpMessage Methods: