Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpMethodBase.addRequestHeader()


                        {
                            httpMethod.addRequestHeader(name, "");
                        }
                        else
                        {
                            httpMethod.addRequestHeader(name, (String) currentValue);
                        }
                    }
                }
            }
        }
View Full Code Here


                }  
            }
        }
       
        // propagate User-Agent, so target site does not think we are a D.O.S. attack
        httpMethod.addRequestHeader( "User-Agent", useragentProperty );
       
        // BOZO - DON'T do this.   default policy seems to be more flexible!!!
        //httpMethod.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
       
        // ...ready to use!
View Full Code Here

        /* Set content type and encoding */
        if (method.getRequestHeader("Content-Type") == null) {
            log.debug("Setting content-type to application/x-www-form-urlencoded; " +
                "charset=" + DEFAULT_ENCODING.toLowerCase());
            method.addRequestHeader("Content-Type",
                    "application/x-www-form-urlencoded; " +
                    "charset=" + DEFAULT_ENCODING.toLowerCase());
        } else {
            log.debug("Not overwriting Content-Type; already set to: " + method.getRequestHeader("Content-Type"));
        }
View Full Code Here

        boolean leaveHttpConnectionOpen = false;
       
        String hostHeader = endpoint.getHost();
        if (endpoint.getPort() != -1)
            hostHeader += ":" + endpoint.getPort();
        method.addRequestHeader("Host", hostHeader);

        int retries = 0;
        while (true) {
            try {
                requestLog.info("Sending Request: " + request.toString());
View Full Code Here

        }

        // No matter what type of HTTP method we're creating, we need to copy
        // all the headers from the request.
        for (Entry<String, String> entry : request.getHeaders().entrySet()) {
            method.addRequestHeader(entry.getKey(), entry.getValue());
        }

        return method;
    }
   
View Full Code Here

        /* Set content type and encoding */
        if (method.getRequestHeader("Content-Type") == null) {
            log.debug("Setting content-type to application/x-www-form-urlencoded; " +
                "charset=" + DEFAULT_ENCODING.toLowerCase());
            method.addRequestHeader("Content-Type",
                    "application/x-www-form-urlencoded; " +
                    "charset=" + DEFAULT_ENCODING.toLowerCase());
        } else {
            log.debug("Not overwriting Content-Type; already set to: " + method.getRequestHeader("Content-Type"));
        }
View Full Code Here

         */
        String hostHeader = endpoint.getHost();
        if (HttpUtils.isUsingNonDefaultPort(endpoint)) {
            hostHeader += ":" + endpoint.getPort();
        }
        method.addRequestHeader("Host", hostHeader);

        // When we release connections, the connection manager leaves them
        // open so they can be reused.  We want to close out any idle
        // connections so that they don't sit around in CLOSE_WAIT.
        httpClient.getHttpConnectionManager().closeIdleConnections(1000 * 30);
 
View Full Code Here

        }

        // No matter what type of HTTP method we're creating, we need to copy
        // all the headers from the request.
        for (Entry<String, String> entry : request.getHeaders().entrySet()) {
            method.addRequestHeader(entry.getKey(), entry.getValue());
        }

        return method;
    }
View Full Code Here

    Header head = get.getResponseHeader("Last-Modified");
    assertNull("We got a Last-Modified header", head);

    // If-Modified-Since tests
    get = getSelectMethod(method);
    get.addRequestHeader("If-Modified-Since", DateUtil.formatDate(new Date()));

    getClient().executeMethod(get);
    checkResponseBody(method, get);
    assertEquals("Expected 200 with If-Modified-Since header. We should never get a 304 here", 200,
        get.getStatusCode());
View Full Code Here

    checkResponseBody(method, get);
    assertEquals("Expected 200 with If-Modified-Since header. We should never get a 304 here", 200,
        get.getStatusCode());

    get = getSelectMethod(method);
    get.addRequestHeader("If-Modified-Since", DateUtil.formatDate(new Date(System.currentTimeMillis()-10000)));
    getClient().executeMethod(get);
    checkResponseBody(method, get);
    assertEquals("Expected 200 with If-Modified-Since header. We should never get a 304 here",
        200, get.getStatusCode());
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.