当前位置: 首页>>代码示例>>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;未经允许,请勿转载。