Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpUriRequest.addHeader()


        httpMethod = new HttpHead(requestUri);
      } else if ("DELETE".equals(methodType)) {
        httpMethod = new HttpDelete(requestUri);
      }
      for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
        httpMethod.addHeader(entry.getKey(), StringUtils.join(entry.getValue(), ','));
      }

      // Disable following redirects.
      if (!request.getFollowRedirects()) {
        httpMethod.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
View Full Code Here


    HttpUriRequest httpMethod = createHttpUriRequest(request.getMethod(), requestUrl);
    for (String name : request.getHeaderNames()) {
      // Skip content length as it is implicitly set when the message entity is set below.
      if (!"Content-Length".equalsIgnoreCase(name)) {
        for (String value : request.getHeaders(name)) {
          httpMethod.addHeader(name, value);
        }
      }
    }

    if (httpMethod instanceof HttpPost) {
View Full Code Here

    }

    // include basic authentication
    if (configuration.isBasicAuth()) {
      String auth = buildBasicAuth(configuration.getUsername(), configuration.getPassword());
      request.addHeader("Authorization", "Basic " + auth);
    }

    // execute request
    HttpResponse httpResponse = httpClient.execute(request);
View Full Code Here

      if (apacheRequest instanceof HttpEntityEnclosingRequest) {
         if (payload != null) {
            addEntityForContent(HttpEntityEnclosingRequest.class.cast(apacheRequest), payload);
         }
      } else {
         apacheRequest.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
      }

      for (Map.Entry<String, String> entry : request.getHeaders().entries()) {
         String header = entry.getKey();
         // apache automatically tries to add content length header
View Full Code Here

      for (Map.Entry<String, String> entry : request.getHeaders().entries()) {
         String header = entry.getKey();
         // apache automatically tries to add content length header
         if (!header.equals(HttpHeaders.CONTENT_LENGTH))
            apacheRequest.addHeader(header, entry.getValue());
      }
      apacheRequest.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
      return apacheRequest;
   }
View Full Code Here

         String header = entry.getKey();
         // apache automatically tries to add content length header
         if (!header.equals(HttpHeaders.CONTENT_LENGTH))
            apacheRequest.addHeader(header, entry.getValue());
      }
      apacheRequest.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
      return apacheRequest;
   }

   public void addEntityForContent(HttpEntityEnclosingRequest apacheRequest, Payload payload) {
      payload = payload instanceof DelegatingPayload ? DelegatingPayload.class.cast(payload).getDelegate() : payload;
View Full Code Here

   @Override
   protected HttpUriRequest convert(HttpRequest request) throws IOException {
      HttpUriRequest returnVal = apacheHCUtils.convertToApacheRequest(request);
      if (request.getPayload() != null && request.getPayload().getContentMetadata().getContentMD5() != null){
         String md5 = base64().encode(asByteSource(request.getPayload().getInput()).hash(md5()).asBytes());
         returnVal.addHeader("Content-MD5", md5);
      }

      return returnVal;
   }
View Full Code Here

      AuthScope scope = new AuthScope(request.getURI().getHost(), request
          .getURI().getPort());
      getCredentialsProvider().setCredentials(scope, creds);
    }

    request.addHeader("User-Agent", Global.USER_AGENT);
    return request;
  }

  protected String processResponse(HttpResponse response)
      throws IllegalStateException, IOException {
View Full Code Here

            return url.openStream();
        }
        final HttpUriRequest request = new HttpGet(url.toExternalForm());
        // We prefer application/ld+json, but fallback to application/json
        // or whatever is available
        request.addHeader("Accept", ACCEPT_HEADER);

        final HttpResponse response = getHttpClient().execute(request);
        final int status = response.getStatusLine().getStatusCode();
        if (status != 200 && status != 203) {
            throw new IOException("Can't retrieve " + url + ", status code: " + status);
View Full Code Here

        httpMethod = new HttpHead(requestUri);
      } else if ("DELETE".equals(methodType)) {
        httpMethod = new HttpDelete(requestUri);
      }
      for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
        httpMethod.addHeader(entry.getKey(), StringUtils.join(entry.getValue(), ','));
      }

      // Disable following redirects.
      if (!request.getFollowRedirects()) {
        httpMethod.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.