當前位置: 首頁>>代碼示例>>Java>>正文


Java MultipartEntityBuilder.setCharset方法代碼示例

本文整理匯總了Java中org.apache.http.entity.mime.MultipartEntityBuilder.setCharset方法的典型用法代碼示例。如果您正苦於以下問題:Java MultipartEntityBuilder.setCharset方法的具體用法?Java MultipartEntityBuilder.setCharset怎麽用?Java MultipartEntityBuilder.setCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.entity.mime.MultipartEntityBuilder的用法示例。


在下文中一共展示了MultipartEntityBuilder.setCharset方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initRequest

import org.apache.http.entity.mime.MultipartEntityBuilder; //導入方法依賴的package包/類
public HttpPost initRequest(final FileUploadParameter parameter) {
	final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
	final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
	final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
	multipartEntity.setCharset(Consts.UTF_8);
	multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Filename",
			new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
	multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解決中文不識別問題
	multipartEntity.addBinaryBody("file", parameter.getUploadFile());
	request.setEntity(multipartEntity.build());
	return request;
}
 
開發者ID:dounine,項目名稱:clouddisk,代碼行數:23,代碼來源:FileUploadParser.java

示例2: main

import org.apache.http.entity.mime.MultipartEntityBuilder; //導入方法依賴的package包/類
public static void main(String args[]){
    HttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("http://localhost:8080/sso-web/upload");
    httpPost.addHeader("Range","bytes=10000-");
    final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
    multipartEntity.setCharset(Consts.UTF_8);
    multipartEntity.setMode(HttpMultipartMode.STRICT);
    multipartEntity.addBinaryBody("file", new File("/Users/huanghuanlai/Desktop/test.java"));
    httpPost.setEntity(multipartEntity.build());
    try {
        HttpResponse response = httpClient.execute(httpPost);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:dounine,項目名稱:clouddisk,代碼行數:17,代碼來源:ClassTest.java

示例3: createMultipartFormEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //導入方法依賴的package包/類
public static HttpEntity createMultipartFormEntity(Map<String, String> parameters, InputStream is) {
	MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
	multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));

	multipartEntityBuilder.addBinaryBody("file", is, ContentType.create("application/octet-stream"), "file");
	for (Entry<String, String> entry : parameters.entrySet()) {
		multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
	}
	return multipartEntityBuilder.build();
}
 
開發者ID:Code4SocialGood,項目名稱:c4sg-services,代碼行數:11,代碼來源:SlackUtils.java

示例4: postBodyAsMultipart

import org.apache.http.entity.mime.MultipartEntityBuilder; //導入方法依賴的package包/類
/**
 * 發送body為multipart form
 * sample
 */
public static String postBodyAsMultipart(String url,Map<String,ContentBody> contentBodies,String charset) throws Exception{
    HttpPost httpPost = new HttpPost(url);
    MultipartEntityBuilder mb = MultipartEntityBuilder.create();
    mb.setCharset(Charset.forName(charset));
    for(Map.Entry<String,ContentBody> entry : contentBodies.entrySet()) {
        mb.addPart(entry.getKey(),entry.getValue());
    }
    httpPost.setEntity(mb.build());
    CloseableHttpResponse response = httpClient.execute(httpPost);
    try {
        HttpEntity entity = response.getEntity();
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            httpPost.abort();
            throw new RuntimeException("HttpClient,error status code :" + statusCode);
        }
        String result = null;
        if (entity != null) {
            result = EntityUtils.toString(entity, "utf-8");
        }
        EntityUtils.consume(entity);
        return result;
    } finally {
        response.close();
    }
}
 
開發者ID:javahongxi,項目名稱:whatsmars,代碼行數:31,代碼來源:HttpUtils.java

示例5: postFile

import org.apache.http.entity.mime.MultipartEntityBuilder; //導入方法依賴的package包/類
private Result postFile(String url, List<String[]> datas, File file) {
    if (!file.exists()) {
        throw new JapiException(file.getAbsolutePath() + " file not exist.");
    }
    HttpPost httpPost = new HttpPost(url);
    Integer tryCount = 0;
    while (reties > tryCount) {
        try {
            final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
            multipartEntity.setCharset(Charset.forName("utf-8"));
            multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            for (String[] nameValue : datas) {
                multipartEntity.addPart(nameValue[0], new StringBody(nameValue[1], ContentType.APPLICATION_JSON));
            }
            multipartEntity.addBinaryBody("file", file);
            httpPost.setEntity(multipartEntity.build());
            httpPost.setHeader("token", token);
            String result = EntityUtils.toString(HTTP_CLIENT.execute(httpPost).getEntity());
            Result result1 = JSON.parseObject(result, ResultImpl.class);
            if (result1.getCode() != 0) {
                throw new JapiException(result1.getMsg());
            }
            return result1;
        } catch (IOException e) {
            if (e instanceof HttpHostConnectException) {
                tryCount++;
                LOGGER.warn("try connect server " + tryCount + " count.");
                try {
                    TimeUnit.SECONDS.sleep(tryTime);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    if (tryCount <= reties) {
        LOGGER.error("server connect failed.");
    }
    return null;
}
 
開發者ID:dounine,項目名稱:japi,代碼行數:41,代碼來源:JapiClientTransfer.java


注:本文中的org.apache.http.entity.mime.MultipartEntityBuilder.setCharset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。