本文整理汇总了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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}