use of org.apache.http.client.methods.HttpRequestWrapper in project webmagic by code4craft.
the class CustomRedirectStrategy method getRedirect.
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
String method = request.getRequestLine().getMethod();
if ("post".equalsIgnoreCase(method)) {
try {
HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request;
httpRequestWrapper.setURI(uri);
httpRequestWrapper.removeHeaders("Content-Length");
return httpRequestWrapper;
} catch (Exception e) {
logger.error("强转为HttpRequestWrapper出错");
}
return new HttpPost(uri);
} else {
return new HttpGet(uri);
}
}
use of org.apache.http.client.methods.HttpRequestWrapper in project metrics by dropwizard.
the class HttpClientMetricNameStrategiesTest method rewriteRequestURI.
private static HttpRequest rewriteRequestURI(HttpRequest request) throws URISyntaxException {
HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
URI uri = URIUtils.rewriteURI(wrapper.getURI(), null, true);
wrapper.setURI(uri);
return wrapper;
}
use of org.apache.http.client.methods.HttpRequestWrapper in project opennms by OpenNMS.
the class HttpClientWrapper method execute.
/**
* Execute the given HTTP method, returning an HTTP response.
*
* Note that when you are done with the response, you must call {@link #closeResponse()} so that it gets cleaned up properly.
*/
public CloseableHttpResponse execute(final HttpUriRequest method) throws ClientProtocolException, IOException {
LOG.debug("execute: " + this.toString() + "; method: " + method.toString());
// override some headers with our versions
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(method);
if (!isEmpty(m_userAgent)) {
requestWrapper.setHeader(HTTP.USER_AGENT, m_userAgent);
}
if (!isEmpty(m_virtualHost)) {
requestWrapper.setHeader(HTTP.TARGET_HOST, m_virtualHost);
}
if (m_version != null) {
if (HttpVersion.HTTP_1_1.equals(m_version) && isEmpty(m_virtualHost)) {
// NMS-7506, set HTTP version to 1.0 if virtual host is not set (since 1.1 requires a virtual host)
requestWrapper.setProtocolVersion(HttpVersion.HTTP_1_0);
} else {
requestWrapper.setProtocolVersion(m_version);
}
}
return getClient().execute(requestWrapper);
}
Aggregations