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