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


Java FilePart.setTransferEncoding方法代码示例

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


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

示例1: multPartURL

import org.apache.commons.httpclient.methods.multipart.FilePart; //导入方法依赖的package包/类
public Response multPartURL(String fileParamName, String url,
		PostParameter[] params, File file, boolean authenticated, String token)
		throws WeiboException {
	PostMethod postMethod = new PostMethod(url);
	try {
		Part[] parts = null;
		if (params == null) {
			parts = new Part[1];
		} else {
			parts = new Part[params.length + 1];
		}
		if (params != null) {
			int i = 0;
			for (PostParameter entry : params) {
				parts[i++] = new StringPart(entry.getName(),
						(String) entry.getValue());
			}
		}
		FilePart filePart = new FilePart(fileParamName, file.getName(),
				file, new MimetypesFileTypeMap().getContentType(file),
				"UTF-8");
		filePart.setTransferEncoding("binary");
		parts[parts.length - 1] = filePart;

		postMethod.setRequestEntity(new MultipartRequestEntity(parts,
				postMethod.getParams()));
		return httpRequest(postMethod, token);
	} catch (Exception ex) {
		throw new WeiboException(ex.getMessage(), ex, -1);
	}
}
 
开发者ID:seagrape,项目名称:kekoa,代码行数:32,代码来源:HttpClient.java

示例2: createFilePart

import org.apache.commons.httpclient.methods.multipart.FilePart; //导入方法依赖的package包/类
private FilePart createFilePart(String name, File value) throws FileNotFoundException
{
    FilePart filePart = new FilePart(name, value);
    filePart.setTransferEncoding(null);
    filePart.setCharSet(null);
    return filePart;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:8,代码来源:SlideShareConnectorImpl.java

示例3: multPartURL

import org.apache.commons.httpclient.methods.multipart.FilePart; //导入方法依赖的package包/类
public Response multPartURL(String fileParamName, String url,
		PostParameter[] params, File file, boolean authenticated)
		throws WeiboException {
	PostMethod postMethod = new PostMethod(url);
	try {
		Part[] parts = null;
		if (params == null) {
			parts = new Part[1];
		} else {
			parts = new Part[params.length + 1];
		}
		if (params != null) {
			int i = 0;
			for (PostParameter entry : params) {
				parts[i++] = new StringPart(entry.getName(),
						(String) entry.getValue());
			}
		}
		FilePart filePart = new FilePart(fileParamName, file.getName(),
				file, new MimetypesFileTypeMap().getContentType(file),
				"UTF-8");
		filePart.setTransferEncoding("binary");
		parts[parts.length - 1] = filePart;

		postMethod.setRequestEntity(new MultipartRequestEntity(parts,
				postMethod.getParams()));
		return httpRequest(postMethod);
	} catch (Exception ex) {
		throw new WeiboException(ex.getMessage(), ex, -1);
	}
}
 
开发者ID:chenhui5416,项目名称:sinaWeiboAutoReply,代码行数:32,代码来源:HttpClient.java

示例4: multPartURL

import org.apache.commons.httpclient.methods.multipart.FilePart; //导入方法依赖的package包/类
public Response multPartURL(String fileParamName,String url,  PostParameter[] params,File file,boolean authenticated) throws WeiboException{
	PostMethod post = new PostMethod(url);
	org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
 	try {
 		long t = System.currentTimeMillis();
 		Part[] parts=null;
 		if(params==null){
 			parts=new Part[1];
 		}else{
 			parts=new Part[params.length+1];
 		}
 		if (params != null ) {
 			int i=0;
   			for (PostParameter entry : params) {
   				parts[i++]=new StringPart( entry.getName(),(String)entry.getValue());
 			}
   		}
 		FilePart filePart=new FilePart(fileParamName,file.getName(), file,new FileType().getMIMEType(file),"UTF-8");
 		filePart.setTransferEncoding("binary");
 		parts[parts.length-1]= filePart;

 		post.setRequestEntity( new MultipartRequestEntity(parts, post.getParams()) );
 		 List<Header> headers = new ArrayList<Header>();

 		 if (authenticated) {
 	            if (oauth == null) {
 	            }
 	            String authorization = null;
 	            if (null != oauth) {
 	                // use OAuth
 	                authorization = oauth.generateAuthorizationHeader( "POST" , url, params, oauthToken);
 	            }else {
 	                throw new IllegalStateException(
 	                        "Neither user ID/password combination nor OAuth consumer key/secret combination supplied");
 	            }
 	            headers.add(new Header("Authorization", authorization));
 	            log("Authorization: " + authorization);
 	        }
 	    client.getHostConfiguration().getParams().setParameter("http.default-headers", headers);
 		client.executeMethod(post);

 		Response response=new Response();
 		response.setResponseAsString(post.getResponseBodyAsString());
 		response.setStatusCode(post.getStatusCode());

 		log("multPartURL URL:" + url + ", result:" + response + ", time:" + (System.currentTimeMillis() - t));
     	return response;
 	} catch (Exception ex) {
 		 throw new WeiboException(ex.getMessage(), ex, -1);
 	} finally {
 		post.releaseConnection();
 		client=null;
 	}
}
 
开发者ID:WildDogTeam,项目名称:demo-android-login,代码行数:55,代码来源:HttpClient.java

示例5: multPartURL

import org.apache.commons.httpclient.methods.multipart.FilePart; //导入方法依赖的package包/类
public Response multPartURL(String fileParamName,String url,  PostParameter[] params,File file,boolean authenticated) throws WeiboException{
	PostMethod post = new PostMethod(url);
	org.apache.commons.httpclient.HttpClient client = getHttpClient();
	try {
 		long t = System.currentTimeMillis();
 		Part[] parts=null;
 		if(params==null){
 			parts=new Part[1];
 		}else{
 			parts=new Part[params.length+1];
 		}
 		if (params != null ) {
 			int i=0;
   			for (PostParameter entry : params) {
   				parts[i++]=new StringPart( entry.getName(),(String)entry.getValue());
 			}
   		}
 		FilePart filePart=new FilePart(fileParamName,file.getName(), file,new MimetypesFileTypeMap().getContentType(file),"UTF-8");
 		filePart.setTransferEncoding("binary");
 		parts[parts.length-1]= filePart;

 		post.setRequestEntity( new MultipartRequestEntity(parts, post.getParams()) );
 		 List<Header> headers = new ArrayList<Header>();

 		 if (authenticated) {
 	            if (oauth == null) {
 	            }
 	            String authorization = null;
 	            if (null != oauth) {
 	                // use OAuth
 	                authorization = oauth.generateAuthorizationHeader( "POST" , url, params, oauthToken);
 	            } else {
 	                throw new IllegalStateException(
 	                        "Neither user ID/password combination nor OAuth consumer key/secret combination supplied");
 	            }
 	            headers.add(new Header("Authorization", authorization));
 	            log("Authorization: " + authorization);
 	        }
 	    client.getHostConfiguration().getParams().setParameter("http.default-headers", headers);
 		client.executeMethod(post);

 		Response response=new Response();
 		response.setResponseAsString(post.getResponseBodyAsString());
 		response.setStatusCode(post.getStatusCode());

 		log("multPartURL URL:" + url + ", result:" + response + ", time:" + (System.currentTimeMillis() - t));
     	return response;
 	} catch (Exception ex) {
 		 throw new WeiboException(ex.getMessage(), ex, -1);
 	} finally {
 		post.releaseConnection();
 		client=null;
 	}
}
 
开发者ID:VysakhV,项目名称:eeplat-social-api,代码行数:55,代码来源:HttpClient.java

示例6: multPartURL

import org.apache.commons.httpclient.methods.multipart.FilePart; //导入方法依赖的package包/类
public Response multPartURL(String fileParamName,String url,  PostParameter[] params,File file,boolean authenticated) throws TBlogException{
	PostMethod post = new PostMethod(url);
	org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
 	try {
 		long t = System.currentTimeMillis();
 		Part[] parts=null;
 		if(params==null){
 			parts=new Part[1];
 		}else{
 			parts=new Part[params.length+1];
 		}
 		if (params != null ) {
 			int i=0;
   			for (PostParameter entry : params) {
   				parts[i++]=new StringPart( entry.getName(),(String)entry.getValue());
 			}
   		}
 		FilePart filePart=new FilePart(fileParamName,file.getName(), file,new MimetypesFileTypeMap().getContentType(file),"UTF-8");
 		filePart.setTransferEncoding("binary");
 		parts[parts.length-1]= filePart;

 		post.setRequestEntity( new MultipartRequestEntity(parts, post.getParams()) );
 		 List<Header> headers = new ArrayList<Header>();   
 		 
 		 if (authenticated) {
 	            if (basic == null && oauth == null) {
 	            }
 	            String authorization = null;
 	            if (null != oauth) {
 	                // use OAuth
 	                authorization = oauth.generateAuthorizationHeader( "POST" , url, params, oauthToken);
 	            } else if (null != basic) {
 	                // use Basic Auth
 	                authorization = this.basic;
 	            } else {
 	                throw new IllegalStateException(
 	                        "Neither user ID/password combination nor OAuth consumer key/secret combination supplied");
 	            }
 	            headers.add(new Header("Authorization", authorization)); 
 	            log("Authorization: " + authorization);
 	        }
 	    client.getHostConfiguration().getParams().setParameter("http.default-headers", headers);
 		client.executeMethod(post);
 
 		Response response=new Response();
 		response.setResponseAsString(post.getResponseBodyAsString());
 		response.setStatusCode(post.getStatusCode());
 		
 		log("multPartURL URL:" + url + ", result:" + response + ", time:" + (System.currentTimeMillis() - t));
     	return response;
 	} catch (Exception ex) {
 		 throw new TBlogException(ex.getMessage(), ex, -1);
 	} finally {
 		post.releaseConnection();
 		client=null;
 	}
}
 
开发者ID:VysakhV,项目名称:eeplat-social-api,代码行数:58,代码来源:HttpClient.java


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