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


Java HttpRequestBase.setHeader方法代码示例

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


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

示例1: addAuthorizationToRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * Sends request to NGB server, retrieves an authorization token and adds it to an input request.
 * This is required for secure requests.
 * @param request to authorize
 */
protected void addAuthorizationToRequest(HttpRequestBase request) {
    try {
        HttpPost post = new HttpPost(serverParameters.getServerUrl() + serverParameters.getAuthenticationUrl());
        StringEntity input = new StringEntity(serverParameters.getAuthPayload());
        input.setContentType(APPLICATION_JSON);
        post.setEntity(input);
        post.setHeader(CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
        post.setHeader(CONTENT_TYPE, "application/x-www-form-urlencoded");
        String result = RequestManager.executeRequest(post);
        Authentication authentication = getMapper().readValue(result, Authentication.class);
        request.setHeader("authorization", "Bearer " + authentication.getAccessToken());
    } catch (IOException e) {
        throw new ApplicationException("Failed to authenticate request", e);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:21,代码来源:AbstractHTTPCommandHandler.java

示例2: addRequiredHeader

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
@Override
protected void addRequiredHeader(HttpRequestBase httpRequestBase) {
    if (!report.isAnonymousTest()) {
        String token = report.getToken();
        if (token != null && token.contains(":")) {
            httpRequestBase.setHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token.getBytes())));
        } else {
            httpRequestBase.setHeader("X-Api-Key", token);
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:12,代码来源:BlazeMeterHttpUtils.java

示例3: setHeader

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * 设置请求头
 *
 * @author gaoxianglong
 */
public static void setHeader(HttpRequestBase request, String headers, ContentType contentType, String charset) {
	if (null == request) {
		return;
	}
	request.setHeader(HTTP.CONTENT_TYPE,
			Optional.ofNullable(contentType.type).orElseGet(() -> ContentType.APPLICATION_XML.type) + ";"
					+ Optional.ofNullable(charset).orElseGet(() -> "UTF-8"));
	if (!StringUtils.isEmpty(headers)) {
		/* 设置请求头参数 */
		JSONObject jsonObj = JSONObject.parseObject(JSONObject.parseObject(headers).get("header").toString());
		jsonObj.keySet().stream().forEach(key -> request.setHeader(key, jsonObj.getString(key)));
	}
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:19,代码来源:ParamUtils.java

示例4: applyDefaultHeaders

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void applyDefaultHeaders(HttpRequestBase httpRequestBase){
	httpRequestBase.setHeader("Accept", "text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8");
	httpRequestBase.setHeader("Accept-Encoding", "gzip, deflate");
	httpRequestBase.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
	httpRequestBase.setHeader("Connection", "keep-alive");
	httpRequestBase.setHeader("DNT", "1");
	httpRequestBase.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0");
}
 
开发者ID:penggle,项目名称:xproject,代码行数:9,代码来源:HttpClientUtils.java

示例5: setRequestHeader

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void setRequestHeader(HttpRequestBase request, Map<String, String> header) {
    if (header != null) {
        for (Map.Entry<String, String> entry : header.entrySet()) {
            request.setHeader(entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:8,代码来源:HttpFetcher.java

示例6: save

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
@Override public HttpResponse save (final IlluminatiEsModel entity) {
    final HttpRequestBase httpPutRequest = new HttpPut(entity.getEsUrl(this.esUrl));

    if (entity.isSetUserAuth() == true) {
        try {
            httpPutRequest.setHeader("Authorization", "Basic " + entity.getEsAuthString());
        } catch (Exception ex) {
            this.logger.error("Sorry. something is wrong in encoding es user auth info. ("+ex.toString()+")");
        }
    }

    ((HttpPut) httpPutRequest).setEntity(this.getHttpEntity(entity));

    HttpResponse httpResponse = null;

    try {
        httpResponse = this.httpClient.execute(httpPutRequest);
    } catch (IOException e) {
        this.logger.error("Sorry. something is wrong in Http Request. ("+e.toString()+")");
    } finally {
        httpPutRequest.releaseConnection();
    }

    if (httpResponse == null) {
        httpResponse = getHttpResponseByData(this.errorCode, "Sorry. something is wrong in Http Request.");
    }

    return httpResponse;
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:30,代码来源:ESclientImpl.java

示例7: setHttpParams

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void setHttpParams(HttpRequestBase httpBase,
		int connectMillisTimeout, int readMillisTimeout,
		boolean handleRedirects) {
	RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
			.setConnectTimeout(connectMillisTimeout)
			.setSocketTimeout(readMillisTimeout)
			.setRedirectsEnabled(handleRedirects).build();

	httpBase.setConfig(requestConfig);
	httpBase.setHeader("accept-encoding", "gzip");
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:12,代码来源:HttpConnectionAdaptor.java

示例8: setAuthorizationHeader

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static HttpRequestBase setAuthorizationHeader (ComplianceTestMetaDataHolder complianceTestMetaDataHolder,
                                                      HttpRequestBase method) {

    String auth = complianceTestMetaDataHolder.getUsername() + ":" + complianceTestMetaDataHolder.getPassword();
    if (!auth.equals(":")) {
        byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
        String authHeader = "Basic " + new String(encodedAuth);
        method.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
    }
    return method;
}
 
开发者ID:wso2-incubator,项目名称:scim2-compliance-test-suite,代码行数:12,代码来源:HTTPClient.java

示例9: setHeaders

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void setHeaders(HttpRequestBase method, Headers headers) {
    if (headers == null) return;

    for (Header h : headers)
        method.setHeader(h.getName(), h.getValue());
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:7,代码来源:HTTPCUtil.java

示例10: setDefaultHeader

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * Adds a default header for HTTP request
 * @param request to add header
 */
protected void setDefaultHeader(HttpRequestBase request) {
    request.setHeader(CONTENT_TYPE, APPLICATION_JSON);
    request.setHeader(CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:9,代码来源:AbstractHTTPCommandHandler.java

示例11: stop

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void stop(boolean unregisterAsListener) {
	if (cleanupThread != null) {
		cleanupThread.dismiss();
		cleanupThread = null;
	}

	setErrorMessage(null);
	setRunningState(RunningState.STOPPED);

	if (unregisterAsListener) {
		try {
			GeoEventHttpClient http = httpClientService.createNewClient();
			String logouturl = host + "/user/logout";
			HttpRequestBase request = HttpUtil.createHttpRequest(http,
					logouturl, "POST", "", "application/json",
					"application/x-www-form-urlencoded", "", LOGGER);
			request.setHeader("Cookie", token);
			
			CloseableHttpResponse response;
			try {
				response = http.execute(request, httpTimeoutValue);
				if (response == null) {
					if (getRunningState() == RunningState.ERROR) {
						LOGGER.info("RECONNECTION_MSG", clientUrl);
						setErrorMessage(null);
						setRunningState(RunningState.STARTED);
					}

					context.setHttpResponse(response);
				} else {
					// log only if we were not in error state already
					if (getRunningState() != RunningState.ERROR) {
						;
					}
				}
			} catch (IOException e) {
				if( getRunningState() != RunningState.ERROR )
				{
					
					String errorMsg = LOGGER.translate("ERROR_ACCESSING_URL", clientUrl, e.getMessage());
					LOGGER.error(errorMsg);
					LOGGER.info(e.getMessage(), e);
					
					// set the error state
					setErrorMessage(errorMsg);
					setRunningState(RunningState.ERROR);
				}
			}

		} catch (Throwable t) {
			// Chances are we're shutting down...
			LOGGER.warn("STOP_ERROR", t.getMessage());
		}
	}
}
 
开发者ID:Esri,项目名称:defense-solutions-proofs-of-concept,代码行数:56,代码来源:MLOBIOutboundTransport.java

示例12: generateHeaders

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * 根据配置自动生成需要的 header
 * @param httpMethod
 * @param setting
 */
private void generateHeaders(HttpRequestBase httpMethod, Setting setting) {
    for(Map.Entry<String,String> headerEntry : setting.getHeader().entrySet()){
        httpMethod.setHeader(headerEntry.getKey(),headerEntry.getValue());
    }
}
 
开发者ID:java-webbee,项目名称:webBee,代码行数:11,代码来源:HttpClientPool.java


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