本文整理汇总了Java中org.apache.http.entity.mime.HttpMultipartMode.BROWSER_COMPATIBLE属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMultipartMode.BROWSER_COMPATIBLE属性的具体用法?Java HttpMultipartMode.BROWSER_COMPATIBLE怎么用?Java HttpMultipartMode.BROWSER_COMPATIBLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.http.entity.mime.HttpMultipartMode
的用法示例。
在下文中一共展示了HttpMultipartMode.BROWSER_COMPATIBLE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: composeMultiPartFormRequest
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;
}
示例2: fileUpload
private static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(postURL);
file = new File("h:/install.txt");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("Filename", new StringBody(file.getName()));
mpEntity.addPart("Filedata", cbFile);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
System.out.println("Now uploading your file into sharesend.com");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
uploadresponse = EntityUtils.toString(resEntity);
}
System.out.println("Upload Response : " + uploadresponse);
System.out.println("Download Link : http://sharesend.com/" + uploadresponse);
httpclient.getConnectionManager().shutdown();
}
示例3: initialize
private void initialize() throws Exception {
responseString = NUHttpClientUtils.getData("http://toutbox.fr/", httpContext);
doc = Jsoup.parse(responseString);
accNo = doc.select("input[name=__accno]").attr("value");
httpPost = new NUHttpPost("http://toutbox.fr/action/Upload/GetUrl/");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("accountId", new StringBody(accNo));
mpEntity.addPart("folderId", new StringBody("0"));
mpEntity.addPart("__RequestVerificationToken", new StringBody("undefined"));
httpPost.setEntity(mpEntity);
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
JSONObject jSon = new JSONObject(responseString);
uploadURL = jSon.getString("Url") + "&ms=" + System.currentTimeMillis();
}
示例4: fileUpload
private static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(postURL);
//httppost.setHeader("Cookie", sidcookie+";"+mysessioncookie);
file = new File("h:/UploadingdotcomUploaderPlugin.java");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("Filename", new StringBody(file.getName()));
mpEntity.addPart("notprivate", new StringBody("false"));
mpEntity.addPart("folder", new StringBody("/"));
mpEntity.addPart("Filedata", cbFile);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
System.out.println("Now uploading your file into zippyshare.com");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
uploadresponse = EntityUtils.toString(resEntity);
}
downloadlink=parseResponse(uploadresponse, "value=\"http://", "\"");
downloadlink="http://"+downloadlink;
System.out.println("Download Link : "+downloadlink);
httpclient.getConnectionManager().shutdown();
}
示例5: fileUpload
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");
}
}
示例6: createPost
/**
* 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;
}
示例7: postFileUpload
@Override
public void postFileUpload(final String uploadServletUrl,
final String fileName, final byte[] bytes) throws IOException {
File file = null;
try {
client = new DefaultHttpClient();
client.getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
// if uploadServletURL is malformed - exception is thrown
new URL(uploadServletUrl);
file = File.createTempFile(fileName, "");
final BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(file));
bos.write(bytes);
bos.flush();
bos.close();
final HttpPost post = new HttpPost(uploadServletUrl);
final MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("file", new FileBody(file,
"application/octet-stream"));
post.setEntity(entity);
client.execute(post);
} catch (final IOException e) {
throw e;
} finally {
client.getConnectionManager().shutdown();
if (file != null && file.exists()) {
file.delete();
}
}
}
示例8: adaptMultipartMode
private static HttpMultipartMode adaptMultipartMode(MultipartMode mode) {
switch (mode) {
case STRICT: return HttpMultipartMode.STRICT;
case BROWSER_COMPATIBLE: return HttpMultipartMode.BROWSER_COMPATIBLE;
case RFC6532: return HttpMultipartMode.RFC6532;
default: throw new IllegalArgumentException("Unknown multipart mode: " + mode);
}
}
示例9: getMultipartEntity
public static MultipartEntity getMultipartEntity(List<FormBodyPart> formBodyParts) {
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(HTTP.UTF_8));
for (FormBodyPart formBodyPart : formBodyParts) {
DebugLog.d(TAG, formBodyPart.getHeader().toString());
multipartEntity.addPart(formBodyPart);
}
return multipartEntity;
}
示例10: doPostByMultipart
/**
* Do a http post with the multipart content type. This method is usually
* used to upload the large size content, such as uploading a file.
*
* @param url
* @param formParams
* @param accessor
* @return
* @throws IOException
* @throws YNoteException
*/
public static HttpResponse doPostByMultipart(String url,
Map<String, Object> formParams, OAuthAccessor accessor)
throws IOException, YNoteException {
HttpPost post = new HttpPost(url);
// for multipart encoded post, only sign with the oauth parameters
// do not sign the our form parameters
Header oauthHeader = getAuthorizationHeader(url, OAuthMessage.POST,
null, accessor);
if (formParams != null) {
// encode our ynote parameters
MultipartEntity entity =
new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
for (Entry<String, Object> parameter : formParams.entrySet()) {
if (parameter.getValue() instanceof File) {
// deal with file particular
entity.addPart(parameter.getKey(),
new FileBody((File)parameter.getValue()));
} else if (parameter.getValue() != null){
entity.addPart(parameter.getKey(), new StringBody(
parameter.getValue().toString(),
Charset.forName(YNoteConstants.ENCODING)));
}
}
post.setEntity(entity);
}
post.addHeader(oauthHeader);
HttpResponse response = client.execute(post);
if ((response.getStatusLine().getStatusCode() / 100) != 2) {
YNoteException e = wrapYNoteException(response);
throw e;
}
return response;
}
示例11: setVi
/**
* 设置用户所在组织的形象设置
*
* @param title
* 软件标题
* @param windowsLogoFile
* windows客户端显示的Logo,为null时代表清除Logo。
* @param androidLogoFile
* android客户端显示的Logo,为null时代表清除Logo。
* @throws Exception
*/
public void setVi(String title, File windowsLogoFile, File androidLogoFile, String group)
throws Exception {
LOG.info("Update vi group of "+ group +" using title:"+title
+",windowLogoPath:" + windowsLogoFile +",androidLogoPath:" + androidLogoFile);
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE, null,
Charset.forName("UTF-8"));
if (title == null) {
title = "";
}
entity.addPart("clientTitle",new StringBody(title, Charset.forName("UTF-8")));
if (windowsLogoFile != null) {
entity.addPart(LOGO_FOR_WINDOWS, new FileBody(windowsLogoFile));
} else {
entity.addPart(LOGO_FOR_WINDOWS, new StringBody(""));
}
if (androidLogoFile != null) {
entity.addPart(LOGO_FOR_ANDROID, new FileBody(androidLogoFile));
} else {
entity.addPart(LOGO_FOR_ANDROID, new StringBody(""));
}
String url = getSetViUrl(group);
postMultipartEntity(entity,url);
}
示例12: setViAndroidLogo
/**
* 设置用户所在组织所用的Android客户端软件的Logo
*
* @param androidLogoFile
* 为null时代表清除Logo。
* @throws Exception
*/
public void setViAndroidLogo(File androidLogoFile,String group) throws Exception {
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE, null,
Charset.forName("UTF-8"));
if (androidLogoFile != null) {
entity.addPart(LOGO_FOR_ANDROID, new FileBody(androidLogoFile));
} else {
entity.addPart(LOGO_FOR_ANDROID, new StringBody(""));
}
String url = getSetViUrl(group);
postMultipartEntity(entity,url);
}
示例13: setViWindowsLogo
/**
* 设置用户所在组织所用的Windows客户端软件的Logo
*
* @param windowsLogoFile
* 为null时代表清除Logo。
* @throws Exception
*/
public void setViWindowsLogo(File windowsLogoFile,String group) throws Exception {
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE, null,
Charset.forName("UTF-8"));
if (windowsLogoFile != null) {
entity.addPart(LOGO_FOR_WINDOWS, new FileBody(windowsLogoFile));
} else {
entity.addPart(LOGO_FOR_WINDOWS, new StringBody(""));
}
String url = getSetViUrl(group);
postMultipartEntity(entity,url);
}
示例14: setViTitle
/**
* 设置用户所在组织所用的客户端软件的标题
*
* @param title
* @throws Exception
*/
public void setViTitle(String title,String group) throws Exception {
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE, null,
Charset.forName("UTF-8"));
if (title == null) {
title = "";
}
entity.addPart("clientTitle",
new StringBody(title, Charset.forName("UTF-8")));
String url = getSetViUrl(group);
postMultipartEntity(entity,url);
}
示例15: testPostRequestWithMultipartEncodedParameters
@Test
public void testPostRequestWithMultipartEncodedParameters() throws Exception {
this.testServer.response = "testPostRequestWithMultipartEncodedParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("age", new StringBody("120"));
reqEntity.addPart("gender", new StringBody("Male"));
httppost.setEntity(reqEntity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostRequestWithMultipartEncodedParameters-params=2;age=120;gender=Male", responseBody);
}