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


Java HttpRequestWithBody.headers方法代码示例

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


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

示例1: download

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
@Override
public HttpResponse download(HttpRequest request) throws DownloaderException {
	if(log.isDebugEnabled()) {
		log.debug("downloading..." + request.getUrl());
	}
	try {
		HttpHost proxy = Proxys.getProxy();
		if(proxy != null) {
			Unirest.setProxy(proxy);
		} else {
			Unirest.setProxy(null);
		}
		request.addHeader("User-Agent", UserAgent.getUserAgent());
		com.mashape.unirest.http.HttpResponse<String> response = null;
		if(request instanceof HttpPostRequest) {
			HttpPostRequest post = (HttpPostRequest)request;
			HttpRequestWithBody httpRequestWithBody = Unirest.post(post.getUrl());
			httpRequestWithBody.headers(post.getHeaders());
			httpRequestWithBody.fields(post.getFields());
			response = httpRequestWithBody.asString();
		} else {
			response = Unirest.get(request.getUrl()).headers(request.getHeaders()).asString();
		}
		String contentType = response.getHeaders().getFirst("Content-Type");
		HttpResponse resp = new HttpResponse();
		resp.setStatus(response.getStatus());
		resp.setRaw(response.getRawBody());
		resp.setContent(response.getBody());
		resp.setContentType(contentType);
		resp.setCharset(getCharset(request, contentType));
		return resp;
	} catch (UnirestException e) {
		throw new DownloaderException(e);
	}
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:36,代码来源:UnirestDownloader.java

示例2: post

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
 * Make a [POST]
 * @param url
 * @param data
 * @param authentication
 * @return resposne Code
 * @throws UnirestException
 */
public int post(String url, Map<String, Object> data, boolean authentication) throws UnirestException{
    Map<String, String> header = new HashMap<>();
    header.put("accept", "application/json");

    if (authentication) {
        header.put("Authorization", "Token " + token);
    }

    HttpRequestWithBody h = Unirest.post(getAPIURL(url));
    h.headers(header);
    h.fields(data);

    if (url.equals("login/")) {
        try {
            JSONObject j = h.asJson().getBody().getObject();
            this.token = j.get("token").toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    return h.asString().getCode();
}
 
开发者ID:paffman,项目名称:WBS-Project,代码行数:32,代码来源:TimeTrackerConnector.java

示例3: patch

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
 * Make a [PATCH]
 * @param url
 * @param data
 * @return response Code
 * @throws UnirestException
 */
public int patch(String url, Map<String, Object> data) throws UnirestException {
    Map<String, String> header = new HashMap<>();
    header.put("accept", "application/json");
    header.put("Authorization", "Token " + token);

    HttpRequestWithBody h = Unirest.patch(getAPIURL(url));
    h.headers(header);
    h.fields(data);

    return h.asJson().getCode();
}
 
开发者ID:paffman,项目名称:WBS-Project,代码行数:19,代码来源:TimeTrackerConnector.java


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