當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。