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


Java Request.body方法代码示例

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


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

示例1: post

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
public Response post(String url, String auth, JsonJavaObject postData, File fileUpload) 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);
	}
	
	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	builder.addBinaryBody("images_file", fileUpload, ContentType.APPLICATION_OCTET_STREAM, fileUpload.getName());
	
	if(postData != null) {
		String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
		builder.addTextBody("classifier_ids", postDataString, ContentType.MULTIPART_FORM_DATA);
	}
	
	HttpEntity multipart = builder.build();
	postRequest.body(multipart);
	
	Response response = executor.execute(postRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:24,代码来源:RestUtil.java

示例2: postFile

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * 上传文件
 *
 * @param url  URL
 * @param name 文件的post参数名称
 * @param file 上传的文件
 * @return
 */
public static String postFile(String url, String name, File file) {
	try {
		HttpEntity reqEntity = MultipartEntityBuilder.create().addBinaryBody(name, file).build();
		Request request = Request.Post(url);
		request.body(reqEntity);
		HttpEntity resEntity = request.execute().returnResponse().getEntity();
		return resEntity != null ? EntityUtils.toString(resEntity) : null;
	} catch (Exception e) {
		logger.error("postFile请求异常," + e.getMessage() + "\n post url:" + url);
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:funtl,项目名称:framework,代码行数:22,代码来源:HttpUtils.java

示例3: patch

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * Patch 请求
 * @param keyPair
 * @param query
 * @return
 */
public static String patch(KeyPair keyPair,String url,Map<String,String> query,String body) throws ApiException {
    URI uri = buildUri(url,query);
    if(uri == null) {
        return "";
    }
    url = uri.toString();
    log.info("patch url:{}",url);

    Request request = Request.Patch(url);
    request.body(new StringEntity(body,"UTF-8"));

    return request(keyPair,request,Constant.METHOD_PATCH,query,body);
}
 
开发者ID:Liangdi,项目名称:zaoshu-java-sdk,代码行数:20,代码来源:HttpUtil.java

示例4: postFile

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * post上传文件
 *
 * @param url      请求地址
 * @param file     post的文件
 * @param fileName post的文件名
 * @return
 */
public static String postFile(String url, File file, String fileName) {
    try {
        HttpEntity reqEntity = MultipartEntityBuilder.create().addBinaryBody(fileName, file).build();
        Request request = Request.Post(url);
        request.body(reqEntity);
        HttpEntity resEntity = request.execute().returnResponse().getEntity();
        String res = resEntity != null ? EntityUtils.toString(resEntity, Wechatboot.charset()) : null;
        logger.debug("http post : {}\n响应数据\n{}", url, res);
        return res;
    } catch (Exception e) {
        throw new RuntimeException("post with file请求异常", e);
    }
}
 
开发者ID:uncoseason,项目名称:wechatboot,代码行数:22,代码来源:Http.java


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