当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethod.setRequestHeader方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.setRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.setRequestHeader方法的具体用法?Java HttpMethod.setRequestHeader怎么用?Java HttpMethod.setRequestHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.HttpMethod的用法示例。


在下文中一共展示了HttpMethod.setRequestHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPreventLoopIncorrectHttpBasicCredentials

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
@Test
public void testPreventLoopIncorrectHttpBasicCredentials() throws Exception {

    // assume http and webdav are on the same host + port
    URL url = new URL(HttpTest.HTTP_BASE_URL);
    Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
    H.getHttpClient().getState()
            .setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);

    final String requestUrl = HttpTest.HTTP_BASE_URL + "/junk?param1=1";
    HttpMethod get = new GetMethod(requestUrl);
    get.setRequestHeader("Referer", requestUrl);
    get.setRequestHeader("User-Agent", "Mozilla/5.0 Sling Integration Test");
    int status = H.getHttpClient().executeMethod(get);
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, status);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:AuthenticationResponseCodeTest.java

示例2: setRequestMac

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
protected void setRequestMac(HttpMethod method, byte[] mac)
{
    if(mac == null)
    {
        throw new AlfrescoRuntimeException("Mac cannot be null");
    }
    method.setRequestHeader(HEADER_MAC, Base64.encodeBytes(mac));    
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:9,代码来源:DefaultEncryptionUtils.java

示例3: setRequestAlgorithmParameters

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void setRequestAlgorithmParameters(HttpMethod method, AlgorithmParameters params) throws IOException
{
    if(params != null)
    {
        method.setRequestHeader(HEADER_ALGORITHM_PARAMETERS, Base64.encodeBytes(params.getEncoded()));
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:12,代码来源:DefaultEncryptionUtils.java

示例4: setProxySpecificHeaders

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
 * Will write the proxy specific headers such as Via and x-forwarded-for.
 * 
 * @param method Method to write the headers to
 * @param request The incoming request, will need to get virtual host.
 * @throws HttpException 
 */
private void setProxySpecificHeaders(HttpMethod method, HttpServletRequest request) throws HttpException {
    String serverHostName = "jEasyExtensibleProxy";
    try {
        serverHostName = InetAddress.getLocalHost().getHostName();   
    } catch (UnknownHostException e) {
        log.error("Couldn't get the hostname needed for headers x-forwarded-server and Via", e);
    }
    
    String originalVia = request.getHeader("via");
    StringBuffer via = new StringBuffer("");
    if (originalVia != null) {
        if (originalVia.indexOf(serverHostName) != -1) {
            log.error("This proxy has already handled the request, will abort.");
            throw new HttpException("Request has a cyclic dependency on this proxy.");
        }
        via.append(originalVia).append(", ");
    }
    via.append(request.getProtocol()).append(" ").append(serverHostName);
     
    method.setRequestHeader("via", via.toString());
    method.setRequestHeader("x-forwarded-for", request.getRemoteAddr());     
    method.setRequestHeader("x-forwarded-host", request.getServerName());
    method.setRequestHeader("x-forwarded-server", serverHostName);
    
    method.setRequestHeader("accept-encoding", "");
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:RequestHandlerBase.java

示例5: setAdditionalHeaders

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void setAdditionalHeaders(final HttpMethod method) {
    for (final Map.Entry<String, String> entry : headers.entrySet()) {
        if (entry.getValue() != null) {
            method.setRequestHeader(entry.getKey(), entry.getValue());
        } else {
            method.removeRequestHeader(entry.getKey());
        }
    }
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:10,代码来源:MethodBuilder.java

示例6: createMethod

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
protected HttpMethod createMethod(Request req) throws IOException
{
    StringBuilder url = new StringBuilder(128);
    url.append(baseUrl);
    url.append("/service/");
    url.append(req.getFullUri());

    // construct method
    HttpMethod httpMethod = null;
    String method = req.getMethod();
    if(method.equalsIgnoreCase("GET"))
    {
        GetMethod get = new GetMethod(url.toString());
        httpMethod = get;
        httpMethod.setFollowRedirects(true);
    }
    else if(method.equalsIgnoreCase("POST"))
    {
        PostMethod post = new PostMethod(url.toString());
        httpMethod = post;
        ByteArrayRequestEntity requestEntity = new ByteArrayRequestEntity(req.getBody(), req.getType());
        if (req.getBody().length > DEFAULT_SAVEPOST_BUFFER)
        {
            post.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
        }
        post.setRequestEntity(requestEntity);
        // Note: not able to automatically follow redirects for POST, this is handled by sendRemoteRequest
    }
    else if(method.equalsIgnoreCase("HEAD"))
    {
        HeadMethod head = new HeadMethod(url.toString());
        httpMethod = head;
        httpMethod.setFollowRedirects(true);
    }
    else
    {
        throw new AlfrescoRuntimeException("Http Method " + method + " not supported");
    }

    if (req.getHeaders() != null)
    {
        for (Map.Entry<String, String> header : req.getHeaders().entrySet())
        {
            httpMethod.setRequestHeader(header.getKey(), header.getValue());
        }
    }
    
    return httpMethod;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:50,代码来源:AbstractHttpClient.java

示例7: setProxyRequestHeaders

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
 * Retrieves all of the headers from the servlet request and sets them on
 * the proxy request
 * 
 * @param httpServletRequest
 *            The request object representing the client's request to the
 *            servlet engine
 * @param httpMethodProxyRequest
 *            The request that we are about to send to the proxy host
 */
private void setProxyRequestHeaders(HttpServletRequest httpServletRequest,
		HttpMethod httpMethodProxyRequest, ProxyHttpConnector proxyHttpConnector) {
	Collection<String> removableHeaders = proxyHttpConnector.getRemovableHeadersSet();
	// Get an Enumeration of all of the header names sent by the client
	Enumeration<String> enumerationOfHeaderNames = GenericUtils.cast(httpServletRequest.getHeaderNames());
	while (enumerationOfHeaderNames.hasMoreElements()) {
		String stringHeaderName = (String) enumerationOfHeaderNames.nextElement();
		if (stringHeaderName.equalsIgnoreCase(STRING_CONTENT_LENGTH_HEADER_NAME)
				|| stringHeaderName.equalsIgnoreCase("Cookie")
				|| removableHeaders.contains(stringHeaderName.toLowerCase())) {
			continue;
		}
		// As per the Java Servlet API 2.5 documentation:
		// Some headers, such as Accept-Language can be sent by clients
		// as several headers each with a different value rather than
		// sending the header as a comma separated list.
		// Thus, we get an Enumeration of the header values sent by the
		// client
		Enumeration<String> enumerationOfHeaderValues = GenericUtils.cast(httpServletRequest
				.getHeaders(stringHeaderName));
		while (enumerationOfHeaderValues.hasMoreElements()) {
			String stringHeaderValue = (String) enumerationOfHeaderValues.nextElement();
			// In case the proxy host is running multiple virtual servers,
			// rewrite the Host header to ensure that we get content from
			// the correct virtual server
			if (stringHeaderName.equalsIgnoreCase(STRING_HOST_HEADER_NAME)) {
				stringHeaderValue = getProxyHostAndPort(proxyHttpConnector);
			} else if (stringHeaderName.equalsIgnoreCase("Referer")) {
				stringHeaderValue = stringHeaderValue.replaceFirst("://[^/]*/[^/]*/", "://"
						+ getProxyHostAndPort(proxyHttpConnector) + proxyHttpConnector.getBaseDir()
						+ (proxyHttpConnector.getBaseDir().endsWith("/") ? "" : "/"));
			}
			Engine.logEngine.debug("(ReverseProxyServlet) Forwarding header: " + stringHeaderName + "="
					+ stringHeaderValue);
			Header header = new Header(stringHeaderName, stringHeaderValue);
			// Set the same header on the proxy request
			httpMethodProxyRequest.setRequestHeader(header);
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:51,代码来源:ReverseProxyServlet.java

示例8: doStart

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
 * for http client
 * 
 * @param args
 * @return
 */
@SuppressWarnings({ "unused", "unchecked" })
public void doStart(Object[] args) {

    HostConfiguration hostconfig = (HostConfiguration) args[0];
    HttpMethod method = (HttpMethod) args[1];
    HttpState state = (HttpState) args[2];

    String httpAction = "";
    method.setRequestHeader("UAV-Client-Src", MonitorServerUtil.getUAVClientSrc(this.applicationId));

    try {
        httpAction = method.getName();
        targetURL = method.getURI().toString();
    }
    catch (URIException e) {
        // ignore
    }

    Map<String, Object> params = new HashMap<String, Object>();

    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, httpAction);
    params.put(CaptureConstants.INFO_CLIENT_APPID, this.applicationId);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "apache.http.Client");

    if (logger.isDebugable()) {
        logger.debug("Invoke START:" + targetURL + "," + httpAction + "," + this.applicationId, null);
    }

    UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
            Monitor.CapturePhase.PRECAP, params);

    // register adapter
    UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter",
            ApacheHttpClient3Adapter.class);

    ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter(
            "com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
            InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params,
            ApacheHttpClient3Adapter.class, args);

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:49,代码来源:ApacheHttpClient3IT.java

示例9: setRequestTimestamp

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
 * Set the timestamp on the HTTP request
 * @param method HttpMethod
 * @param timestamp (ms, in UNIX time)
 */
protected void setRequestTimestamp(HttpMethod method, long timestamp)
{
    method.setRequestHeader(HEADER_TIMESTAMP, String.valueOf(timestamp));        
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:10,代码来源:DefaultEncryptionUtils.java


注:本文中的org.apache.commons.httpclient.HttpMethod.setRequestHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。