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


Java MultipartEntity類代碼示例

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


MultipartEntity類屬於org.apache.http.entity.mime包,在下文中一共展示了MultipartEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uploadFile

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
public void uploadFile(String url, byte[] data) throws CytomineException {

		try {
			HttpClient client = null;
			MultipartEntity entity = new MultipartEntity();
			entity.addPart("files[]", new ByteArrayBody(data, new Date().getTime() + "file"));
			client = new HttpClient(publicKey, privateKey, getHost());
			client.authorize("POST", url, entity.getContentType().getValue(), "application/json,*/*");
			client.connect(getHost() + url);
			int code = client.post(entity);
			String response = client.getResponseData();
			log.debug("response=" + response);
			client.disconnect();
			JSONObject json = createJSONResponse(code, response);
		} catch (IOException e) {
			throw new CytomineException(e);
		}
	}
 
開發者ID:cytomine,項目名稱:Cytomine-java-client,代碼行數:19,代碼來源:Cytomine.java

示例2: composeMultiPartFormRequest

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private HttpPost composeMultiPartFormRequest(final String uri, final Parameters parameters, final Map<String, ContentBody> files) {
	HttpPost request = new HttpPost(uri);
	MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

	try {
		Charset utf8 = Charset.forName("UTF-8");
		for(Parameter param : parameters)
			if(param.isSingleValue())
				multiPartEntity.addPart(param.getName(), new StringBody(param.getValue(), utf8));
			else
				for(String value : param.getValues())
					multiPartEntity.addPart(param.getName(), new StringBody(value, utf8));
	} catch (UnsupportedEncodingException e) {
		throw MechanizeExceptionFactory.newException(e);
	}

	List<String> fileNames = new ArrayList<String>(files.keySet());
	Collections.sort(fileNames);
	for(String name : fileNames) {
		ContentBody contentBody = files.get(name);
		multiPartEntity.addPart(name, contentBody);
	}
	request.setEntity(multiPartEntity);
	return request;
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:26,代碼來源:RequestBuilder.java

示例3: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private static void fileUpload() throws Exception {

        file = new File("/home/vigneshwaran/VIGNESH/dinesh.txt");
        httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);


        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("Filename", new StringBody(file.getName()));
        mpEntity.addPart("ssd", new StringBody(ssd));
        mpEntity.addPart("Filedata", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into slingfile.com");
        HttpResponse response = httpclient.execute(httppost);
//        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        System.out.println(EntityUtils.toString(response.getEntity())); 

    }
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:22,代碼來源:SlingFileUploaderPlugin.java

示例4: postData

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private static int postData(String url, byte[] encryptedBytes, byte[] encryptedSecretKey, byte[] signature, String serviceName) throws IOException {
	MultipartEntity multipartEntity = new MultipartEntity();
	
	String filename=serviceName+'_'+System.currentTimeMillis()+".hl7";
	multipartEntity.addPart("importFile", new ByteArrayBody(encryptedBytes, filename));		
	multipartEntity.addPart("key", new StringBody(new String(Base64.encodeBase64(encryptedSecretKey), MiscUtils.DEFAULT_UTF8_ENCODING)));
	multipartEntity.addPart("signature", new StringBody(new String(Base64.encodeBase64(signature), MiscUtils.DEFAULT_UTF8_ENCODING)));
	multipartEntity.addPart("service", new StringBody(serviceName));
	multipartEntity.addPart("use_http_response_code", new StringBody("true"));

	HttpPost httpPost = new HttpPost(url);
	httpPost.setEntity(multipartEntity);

	HttpClient httpClient = getTrustAllHttpClient();
	httpClient.getParams().setParameter("http.connection.timeout", CONNECTION_TIME_OUT);
	HttpResponse httpResponse = httpClient.execute(httpPost);
	int statusCode=httpResponse.getStatusLine().getStatusCode();
	logger.debug("StatusCode:" + statusCode);
	return (statusCode);
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:21,代碼來源:SendingUtils.java

示例5: put2

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
public int put2(byte[] data) throws Exception {
        log.debug("Put " + URL.getPath());
        HttpPut httpPut = new HttpPut(URL.getPath());
        if (isAuthByPrivateKey) httpPut.setHeaders(headersArray);
        log.debug("Put send :" + data.length);

//        InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(data), data.length);
//        reqEntity.setContentType("binary/octet-stream");
//        reqEntity.setChunked(false);
//
//        BufferedHttpEntity myEntity = null;
//                   try {
//                       myEntity = new BufferedHttpEntity(reqEntity);
//                   } catch (IOException e) {
//                       // TODO Auto-generated catch block
//                       e.printStackTrace();
//                   }
        MultipartEntity myEntity = new MultipartEntity();
        myEntity.addPart("files[]",new ByteArrayBody(data,"toto")) ;
        //int code = client.post(entity);


        httpPut.setEntity(myEntity);
        response = client.execute(targetHost, httpPut, localcontext);
        return response.getStatusLine().getStatusCode();
    }
 
開發者ID:cytomine,項目名稱:Cytomine-client-autobuilder,代碼行數:27,代碼來源:HttpClient.java

示例6: editWikiPage

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
public void editWikiPage(String[][] currentCommentInformation, String subreddit) throws IOException {


        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost("https://www.reddit.com/r/"+subreddit+"/api/wiki/edit");
        MultipartEntity nvps = new MultipartEntity();
        httpPost.addHeader("User-Agent","User-Agent: LGG Bot (by /u/amdphenom");
        httpPost.addHeader("Cookie","reddit_session=" + user.getCookie());
        nvps.addPart("r", new StringBody(subreddit));
        nvps.addPart("uh", new StringBody(user.getModhash()));
        nvps.addPart("formid", new StringBody("image-upload"));
        httpPost.setEntity(nvps);

        CloseableHttpResponse response2 = httpclient.execute(httpPost);

        try {
            System.out.println(response2.getStatusLine());
            HttpEntity entity2 = response2.getEntity();
            // do something useful with the response body
            // and ensure it is fully consumed
            EntityUtils.consume(entity2);
        } finally {
            response2.close();
        }
    }
 
開發者ID:jaredkaczynski,項目名稱:LGSubredditHelper,代碼行數:26,代碼來源:UpdateWiki.java

示例7: createCredentials

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
/**
 * Create a Credentials file with the provided authentication parameters
 *
 * @param login username
 * @param pass  password
 * @param ssh   private ssh key
 * @return the the Credentials file as a base64 String
 * @throws RestServerException
 * @throws ServiceException
 */
@Override
public String createCredentials(String login, String pass, String ssh)
        throws RestServerException, ServiceException {
    HttpPost method = new HttpPost(SchedulerConfig.get().getRestUrl() + "/scheduler/createcredential");

    try {
        MultipartEntity entity = createLoginPasswordSSHKeyMultipart(login, pass, ssh);
        method.setEntity(entity);

        HttpResponse response = httpClient.execute(method);
        String responseAsString = convertToString(response.getEntity().getContent());

        switch (response.getStatusLine().getStatusCode()) {
            case 200:
                return responseAsString;
            default:
                throw new RestServerException(response.getStatusLine().getStatusCode(), responseAsString);
        }
    } catch (IOException e) {
        throw new ServiceException(e.getMessage());
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:ow2-proactive,項目名稱:scheduling-portal,代碼行數:35,代碼來源:SchedulerServiceImpl.java

示例8: createCredentials

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
/**
 * Create a Credentials file with the provided authentication parameters
 *
 * @param login username
 * @param pass  password
 * @param ssh   private ssh key
 * @return the the Credentials file as a base64 String
 * @throws ServiceException
 */
public String createCredentials(String login, String pass, String ssh)
        throws RestServerException, ServiceException {
    HttpPost httpPost = new HttpPost(RMConfig.get().getRestUrl() + "/scheduler/createcredential");

    try {
        MultipartEntity entity = createLoginPasswordSSHKeyMultipart(login, pass, ssh);

        httpPost.setEntity(entity);

        HttpResponse response = httpClient.execute(httpPost);
        String responseAsString = convertToString(response.getEntity().getContent());

        switch (response.getStatusLine().getStatusCode()) {
            case 200:
                return responseAsString;
            default:
                throw new RestServerException(response.getStatusLine().getStatusCode(), responseAsString);
        }
    } catch (Exception e) {
        LOGGER.warn("Failed to create credentials", e);
        throw new ServiceException(e.getMessage());
    } finally {
        httpPost.releaseConnection();
    }
}
 
開發者ID:ow2-proactive,項目名稱:scheduling-portal,代碼行數:35,代碼來源:RMServiceImpl.java

示例9: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private void fileUpload() throws Exception {
    httpPost = new NUHttpPost(postURL);
    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    mpEntity.addPart("Filename", new StringBody(file.getName()));
    mpEntity.addPart("notprivate", new StringBody("false"));
    mpEntity.addPart("folder", new StringBody("/"));
    mpEntity.addPart("Filedata", createMonitoredFileBody()); 
    httpPost.setHeader("Cookie", usercookie);
    httpPost.setEntity(mpEntity);
    uploading();
    NULogger.getLogger().info("Now uploading your file into zippyshare.com");
    httpResponse = httpclient.execute(httpPost);
    gettingLink();
    HttpEntity resEntity = httpResponse.getEntity();
    if (resEntity != null) {
        uploadresponse = EntityUtils.toString(resEntity);
        downloadlink = StringUtils.stringBetweenTwoStrings(uploadresponse, "value=\"http://", "\"");
        downloadlink = "http://" + downloadlink;
        NULogger.getLogger().log(Level.INFO, "Download Link : {0}", downloadlink);
        downURL=downloadlink;
        
    }else{
        throw new Exception("ZippyShare server problem or Internet connectivity problem");
    }

}
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:27,代碼來源:ZippyShare.java

示例10: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private static void fileUpload() throws Exception {

        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        httppost.setHeader("Cookie", sidcookie);
        file = new File("h:/install.txt");
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("filepc", cbFile);
        mpEntity.addPart("server", new StringBody(server));
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into uploadbox.com");
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.getStatusLine());
        uploadresponse = response.getLastHeader("Location").getValue();
        uploadresponse = getData(uploadresponse);
        downloadlink = parseResponse(uploadresponse, "name=\"loadlink\" id=\"loadlink\" class=\"text\" onclick=\"this.select();\" value=\"", "\"");
        deletelink = parseResponse(uploadresponse, "name=\"deletelink\" id=\"deletelink\" class=\"text\" onclick=\"this.select();\" value=\"", "\"");
        System.out.println("Download link " + downloadlink);
        System.out.println("deletelink : " + deletelink);
    }
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:23,代碼來源:UploadBoxUploaderPlugin.java

示例11: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
public static void fileUpload() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        //reqEntity.addPart("string_field",new StringBody("field value"));
        FileBody bin = new FileBody(new File("/home/vigneshwaran/VIGNESH/naruto.txt"));
        reqEntity.addPart("fff", bin);
        httppost.setEntity(reqEntity);
        System.out.println("Now uploading your file into 2shared.com. Please wait......................");
        HttpResponse response = httpclient.execute(httppost);
//        HttpEntity resEntity = response.getEntity();
//
//        if (resEntity != null) {
//            String page = EntityUtils.toString(resEntity);
//            System.out.println("PAGE :" + page);
//        }
    }
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:18,代碼來源:TwoSharedUploaderPlugin.java

示例12: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private static void fileUpload() throws IOException { 
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(postURL);
    file = new File("h:/UploadingdotcomUploaderPlugin.java");
    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("emai", new StringBody("Free"));
    mpEntity.addPart("upload_range", new StringBody("1"));
    mpEntity.addPart("upfile_0", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("executing request " + httppost.getRequestLine());
    System.out.println("Now uploading your file into MegaShare.com");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    uploadresponse = response.getLastHeader("Location").getValue();
    System.out.println("Upload response : "+uploadresponse);
    System.out.println(response.getStatusLine());

    httpclient.getConnectionManager().shutdown();
}
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:21,代碼來源:MegaShareUploaderPlugin.java

示例13: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
private void fileUpload() throws Exception {
        httpPost = new NUHttpPost(postURL);
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        mpEntity.addPart("MAX_FILE_SIZE", new StringBody(Long.toString(maxFileSizeLimit)));
        mpEntity.addPart("owner", new StringBody(""));
        mpEntity.addPart("pin", new StringBody(pin));
        mpEntity.addPart("base", new StringBody(base));
        mpEntity.addPart("host", new StringBody("letitbit.net"));
        mpEntity.addPart("source", new StringBody("newlib.wm-panel.com"));
        mpEntity.addPart("folder", new StringBody(""));
        mpEntity.addPart("file0", createMonitoredFileBody());
        httpPost.setEntity(mpEntity);
        NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
        uploading();
        NULogger.getLogger().info("Now uploading your file into letitbit.net");
        HttpResponse response = httpclient.execute(httpPost, httpContext);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        }
//  
        NULogger.getLogger().log(Level.INFO, "Upload response : {0}", uploadresponse);
    }
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:25,代碼來源:Letitbit.java

示例14: fileUpload

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
public void fileUpload() throws Exception {
    httpPost = new NUHttpPost("http://www.gigasize.com/uploadie");
    MultipartEntity mpEntity = new MultipartEntity();
    mpEntity.addPart("UPLOAD_IDENTIFIER", new StringBody(uploadid));
    mpEntity.addPart("sid", new StringBody(sid));
    mpEntity.addPart("fileUpload1", createMonitoredFileBody());
    httpPost.setEntity(mpEntity);
    uploading();
    NULogger.getLogger().info("Now uploading your file into Gigasize...........................");
    HttpResponse response = httpclient.execute(httpPost, httpContext);
    HttpEntity resEntity = response.getEntity();
    NULogger.getLogger().info(response.getStatusLine().toString());
    if (resEntity != null) {
        sid = "";
        sid = EntityUtils.toString(resEntity);
        NULogger.getLogger().log(Level.INFO, "After upload sid value : {0}", sid);
    } else {
        throw new Exception("There might be a problem with your internet connection or GigaSize server problem. Please try after some time :(");
    }
}
 
開發者ID:Neembuu-Uploader,項目名稱:neembuu-uploader,代碼行數:21,代碼來源:GigaSize.java

示例15: createPost

import org.apache.http.entity.mime.MultipartEntity; //導入依賴的package包/類
/**
 * Create Post Request with FormBodyPart body
 */
public HttpPost createPost(String uri, LinkedList<FormBodyPart> partsList) {
    HttpPost postRequest = new HttpPost(uri);
    MultipartEntity multipartRequest = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    for (FormBodyPart part : partsList) {
        multipartRequest.addPart(part);
    }
    postRequest.setEntity(multipartRequest);
    return postRequest;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:13,代碼來源:HttpUtils.java


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