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


Java HttpRequestWithBody.asString方法代码示例

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


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

示例1: save

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
@Override public <T extends Event<?>> void save(T event) throws Exception {
	Map<String, String> data = null;
	if (event instanceof ChangeEvent) {
		ChangeEvent e = (ChangeEvent) event;
		data = handle(e);
		if (data != null) {
			String uri = this.props.get("uri") + "/metrics";
			HttpRequestWithBody request = Unirest.post(uri);
			request.queryString("metric", e.variable());
			request.queryString("value", data.get("value"));
			data.remove("value");
			for (String tag : data.keySet()) {
				request.queryString("label[" + tag + "]", data.get(tag));
			}
			HttpResponse<String> response = request.asString();
			if (Boolean.valueOf(this.props.get("output_responses"))) {
				System.out.println(response.getStatusText() + "\t"
						+ response.getBody());
			}
		}
	}

}
 
开发者ID:unicesi,项目名称:pascani,代码行数:24,代码来源:FNordMetric.java

示例2: login

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
 * Use this method to get a new TelegramBot instance with the selected auth token
 *
 * @param authToken The bots auth token
 *
 * @return A new TelegramBot instance or null if something failed
 */
public static TelegramBot login(String authToken) {

    try {

        HttpRequestWithBody request = Unirest.post(API_URL + "bot" + authToken + "/getMe");
        HttpResponse<String> response = request.asString();
        JSONObject jsonResponse = Utils.processResponse(response);

        if (jsonResponse != null && Utils.checkResponseStatus(jsonResponse)) {

            JSONObject result = jsonResponse.getJSONObject("result");

            return new TelegramBot(authToken, result.getInt("id"), result.getString("first_name"), result.getString("username"));
        }
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:28,代码来源:TelegramBot.java

示例3: uploadOne

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
@Test
public void uploadOne() throws IOException {
    // Create temp file.
    File temp = File.createTempFile("myimage", ".image");
    Files.write("Hello world", temp, Charsets.UTF_8);


    try {
        HttpRequestWithBody post = Unirest.post("http://localhost:4849/upload/image");
        post.field("name", "bingoo.txt");
        post.field("file", temp);
        HttpResponse<String> file = post
            .asString();
        System.out.println(file.getStatus());

    } catch (Exception e) {
        e.printStackTrace();
    }


    temp.delete();
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:23,代码来源:PostTest.java

示例4: 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


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