Example usage for org.apache.commons.httpclient.methods MultipartPostMethod addRequestHeader

List of usage examples for org.apache.commons.httpclient.methods MultipartPostMethod addRequestHeader

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods MultipartPostMethod addRequestHeader.

Prototype

@Override
public void addRequestHeader(String headerName, String headerValue) 

Source Link

Document

Adds the specified request header, NOT overwriting any previous value.

Usage

From source file:org.bibsonomy.rest.client.worker.impl.PostWorker.java

public Reader perform(final String url, final File file) throws ErrorPerformingRequestException {
    LOGGER.debug("POST Multipart: URL: " + url);

    if (this.proxyHost != null) {
        this.getHttpClient().getHostConfiguration().setProxy(this.proxyHost, this.proxyPort);
    }/*from  w w w  . j  av a 2 s .c  o m*/

    // TODO: remove deprecated method
    final MultipartPostMethod post = new MultipartPostMethod(url);

    post.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
    post.addRequestHeader(HeaderUtils.HEADER_AUTHORIZATION,
            HeaderUtils.encodeForAuthorization(this.username, this.apiKey));
    post.addRequestHeader("Content-Type", "multipart/form-data");

    try {
        post.addParameter("file", file);

        this.getHttpClient().getHttpConnectionManager().getParams().setConnectionTimeout(5000);

        this.httpResult = this.getHttpClient().executeMethod(post);
        LOGGER.debug("HTTP result: " + this.httpResult);
        LOGGER.debug("response:\n" + post.getResponseBodyAsString());
        LOGGER.debug("===================================================");
        return new StringReader(post.getResponseBodyAsString());
    } catch (final IOException e) {
        LOGGER.debug(e.getMessage(), e);
        throw new ErrorPerformingRequestException(e);
    } finally {
        post.releaseConnection();
    }
}