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


Java Request.addHeader方法代码示例

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


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

示例1: put

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * Send PUT request with authorization header
 * @param url - The url of the POST request
 * @param auth - String for authorization header
 * @param putData - The body of the PUT
 */
public Response put(String url, String auth, JsonJavaObject putData) throws URISyntaxException, IOException, JsonException {
	URI normUri = new URI(url).normalize();
	Request putRequest = Request.Put(normUri);
	
	//Add auth header
	if(StringUtil.isNotEmpty(auth)) {
		putRequest.addHeader("Authorization", auth);
	}
	
	//Add put data
	String putDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, putData);
	if(putData != null) {
		putRequest = putRequest.bodyString(putDataString, ContentType.APPLICATION_JSON);
	}
	
	Response response = executor.execute(putRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:25,代码来源:RestUtil.java

示例2: addHeadersToRequest

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
@VisibleForTesting
void addHeadersToRequest(final Request request, final URL trackerAnnounceURI) {
    final int port = trackerAnnounceURI.getPort();
    // Add Host header first to prevent Request appending it at the end
    request.addHeader("Host", trackerAnnounceURI.getHost() + (port == -1 ? "" : ":" + port));

    //noinspection SimplifyStreamApiCallChains
    this.headers.stream().forEachOrdered(header -> {
        final String name = header.getKey();
        final String value = header.getValue()
                .replaceAll("\\{java}", System.getProperty("java.version"))
                .replaceAll("\\{os}", System.getProperty("os.name"))
                .replaceAll("\\{locale}", Locale.getDefault().toLanguageTag());

        request.addHeader(name, value);
    });

    // if Connection header was not set, we append it. Apache HttpClient will add it what so ever, so prefer "Close" over "keep-alive"
    final boolean hasConnectionHeader = this.headers.stream()
            .anyMatch(header -> "Connection".equalsIgnoreCase(header.getKey()));
    if (!hasConnectionHeader) {
        request.addHeader("Connection", "Close");
    }
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:25,代码来源:BitTorrentClient.java

示例3: post

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * Send POST request with authorization header and additional headers
 * @param url - The url of the POST request
 * @param auth - String for authorization header
 * @param headers - Hashmap of headers to add to the request
 * @param postData - The body of the POST
 * @return the Response to the POST request
 */
public Response post(String url, String auth, HashMap<String, String> headers, JsonJavaObject postData) throws JsonException, IOException, URISyntaxException {
	URI normUri = new URI(url).normalize();
	Request postRequest = Request.Post(normUri);
	
	//Add all headers
	if(StringUtil.isNotEmpty(auth)) {
		postRequest.addHeader("Authorization", auth);
	}
	if(headers != null && headers.size() > 0){
		for (Map.Entry<String, String> entry : headers.entrySet()) {
			postRequest.addHeader(entry.getKey(), entry.getValue());
		}
	}

	String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
	Response response = executor.execute(postRequest.bodyString(postDataString, ContentType.APPLICATION_JSON));
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:27,代码来源:RestUtil.java

示例4: prepareRequest

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
private void prepareRequest(Request apacheRequest) {
    if (getUserAgent() != null) {
        apacheRequest.userAgent(getUserAgent());
    }
    if (getConnectTimeout() != null) {
        apacheRequest.connectTimeout(getConnectTimeout());
    }
    if (getReadTimeout() != null) {
        apacheRequest.socketTimeout(getReadTimeout());
    }

    if (!requestHeaders.isEmpty()) {
        for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
            apacheRequest.addHeader(entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:DorsetProject,项目名称:dorset-framework,代码行数:18,代码来源:ApacheHttpClient.java

示例5: getToken

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
public static String getToken(String code){
	try{
		Request request = Request.Post("https://discordapp.com/api/oauth2/token"
				+"?grant_type=authorization_code"
				+"&code="+code
				+"&redirect_uri="+URLEncoder.encode(Pokebot.config.REDIRECT_URL, "UTF-8")
				+"&client_id="+Pokebot.config.CLIENT_ID
				+"&client_secret="+Pokebot.config.CLIENT_SECRET);
				request.addHeader("Content-Type", "application/x-www-form-urlencoded");
		TokenResponse tokenResponse = gson.fromJson(request.execute().returnContent().asString(), TokenResponse.class);
		if(tokenResponse.access_token == null){
			System.err.println(tokenResponse.error);
			return null;
		}
		return tokenResponse.access_token;
	} catch(IOException e){
		e.printStackTrace();
		System.err.println("\nUnable to get token");
	}
	return null;
}
 
开发者ID:Coolway99,项目名称:Discord-Pokebot,代码行数:22,代码来源:OAuth_Handler.java

示例6: addRestComm

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static void addRestComm(Request request, Map<String, Object> args) {
    request.connectTimeout(connectTimeout);
    request.userAgent("Mozilla");
    request.socketTimeout(socketTimeout);
    if (args.containsKey("header")) {
        Object object = args.get("header");
        if (object instanceof Map) {
            Map<String, String> mapHeader = (Map<String, String>) object;
            for (String o : mapHeader.keySet()) {
                request.addHeader(o, mapHeader.get(o));
            }
        }
    }
}
 
开发者ID:lftao,项目名称:restclient,代码行数:16,代码来源:RestUtils.java

示例7: applyRequestHeaders

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
void applyRequestHeaders(final Request request, final Map<String, String> requestHeaders) {

        if (requestHeaders == null)
            return;

        for (Map.Entry<String, String> h : requestHeaders.entrySet()) {
            request.addHeader(h.getKey(), h.getValue());
        }
    }
 
开发者ID:mgtechsoftware,项目名称:smockin,代码行数:10,代码来源:HttpClientServiceImpl.java

示例8: get

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * Send basic GET request with authorization header
 */
public Response get(String url, String auth) throws URISyntaxException, IOException {
	URI normUri = new URI(url).normalize();
	Request getRequest = Request.Get(normUri);
	if(StringUtil.isNotEmpty(auth)) {
		getRequest.addHeader("Authorization", auth);
	}
	Response response = executor.execute(getRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:13,代码来源:RestUtil.java

示例9: downloader

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * 下载,并返回string
 * @throws IOException 
 * @throws ClientProtocolException 
 **/
public String downloader(String url) throws ClientProtocolException, IOException {
	String res = "";
	Request rq = Request.Get(url).connectTimeout(this.timeout);
	if (this.agent != null)
		rq = rq.userAgent(this.agent);
	if (this.cookie != null)
		rq = rq.addHeader("Cookie", this.cookie);
	if (this.proxy != null)
		rq = rq.viaProxy(this.proxy);
	res = rq.execute().returnContent().asString();
	return res;
}
 
开发者ID:luohaha,项目名称:jlitespider,代码行数:18,代码来源:Network.java

示例10: httpGet

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
protected String httpGet(String url, String encoding,
                         Map<String, String> headers) throws IOException, CredentialInvalidException {
    Request request = Request.Get(url).connectTimeout(15000)
            .socketTimeout(15000);
    if (headers != null) {
        for (Entry<String, String> entry : headers.entrySet()) {
            request.addHeader(entry.getKey(), entry.getValue());
        }
    }
    return executeRequest(encoding, request);
}
 
开发者ID:vertretungsplanme,项目名称:substitution-schedule-parser,代码行数:12,代码来源:BaseParser.java

示例11: httpPost

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
protected String httpPost(String url, String encoding,
                          List<NameValuePair> formParams, Map<String, String> headers)
        throws IOException, CredentialInvalidException {
    Request request = Request.Post(url).bodyForm(formParams)
            .connectTimeout(15000).socketTimeout(15000);
    if (headers != null) {
        for (Entry<String, String> entry : headers.entrySet()) {
            request.addHeader(entry.getKey(), entry.getValue());
        }
    }
    return executeRequest(encoding, request);
}
 
开发者ID:vertretungsplanme,项目名称:substitution-schedule-parser,代码行数:13,代码来源:BaseParser.java


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