Code example for HttpUriRequest

Methods: addHeader, getURI

0
        callMethod(post, operation);
    } 
 
    private void callMethod(HttpUriRequest request, Operation operation) throws IOException {
        // Specify GData protocol version 2.0. 
        request.addHeader("GData-Version", "2");
 
        // Indicate support for gzip-compressed responses. 
        request.addHeader("Accept-Encoding", "gzip");
 
        // Specify authorization token if provided. 
        String authToken = mAuthToken;
        if (!TextUtils.isEmpty(authToken)) {
            request.addHeader("Authorization", "GoogleLogin auth=" + authToken);
        } 
 
        // Specify the ETag of a prior response, if available. 
        String etag = operation.inOutEtag;
        if (etag != null) {
            request.addHeader("If-None-Match", etag);
        } 
 
        // Execute the HTTP request. 
        HttpResponse httpResponse = null;
        try { 
            httpResponse = mHttpClient.execute(request);
        } catch (IOException e) {
            Log.w(TAG, "Request failed: " + request.getURI());
            throw e;
        } 
 
        // Get the status code and response body. 
        int status = httpResponse.getStatusLine().getStatusCode();