本文整理汇总了Java中org.apache.http.entity.mime.content.StringBody类的典型用法代码示例。如果您正苦于以下问题:Java StringBody类的具体用法?Java StringBody怎么用?Java StringBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringBody类属于org.apache.http.entity.mime.content包,在下文中一共展示了StringBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initRequest
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
public HttpPost initRequest(final FileUploadParameter parameter) {
final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setCharset(Consts.UTF_8);
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
multipartEntity.addPart("Filename",
new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解决中文不识别问题
multipartEntity.addBinaryBody("file", parameter.getUploadFile());
request.setEntity(multipartEntity.build());
return request;
}
示例2: startOnline
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
public String startOnline() throws IOException {
String uri = address + "api/active/receiver/start";
LinkedList<FormBodyPart> partsList = new LinkedList<>();
partsList.add(new FormBodyPart("token", new StringBody(token)));
partsList.add(new FormBodyPart("projectKey", new StringBody(project)));
partsList.add(new FormBodyPart("title", new StringBody(title)));
JSONObject obj = queryObject(createPost(uri, partsList), 201);
return address + "gui/active/" + obj.optString("OnlineID", "N/A") + "/";
}
示例3: postData
import org.apache.http.entity.mime.content.StringBody; //导入依赖的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);
}
示例4: composeMultiPartFormRequest
import org.apache.http.entity.mime.content.StringBody; //导入依赖的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;
}
示例5: newFileBody
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
private static FormBodyPart newFileBody(final String parameterName, final String fileName, final String fileContent)
throws Exception {
return new FormBodyPart(
parameterName,
new StringBody(fileContent, ContentType.TEXT_PLAIN) {
@Override
public String getFilename() {
return fileName;
}
@Override
public String getTransferEncoding() {
return "binary";
}
@Override
public String getMimeType() {
return "";
}
@Override
public String getCharset() {
return null;
}
});
}
示例6: uploadDatabase
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
private void uploadDatabase() throws Exception {
tempDB = File.createTempFile("temp_", ".sqlite", serviceModule.getDirectoryPath());
databaseManager.mergeRecord().dumpDatabaseTo(tempDB);
// check if database is empty
if (databaseManager.mergeRecord().isEmpty(tempDB)) {
FLog.d("database is empty");
return;
}
HashMap<String, ContentBody> extraParts = new HashMap<String, ContentBody>();
extraParts.put("user", new StringBody(databaseManager.getUserId()));
if (!uploadFile("db",
Request.DATABASE_UPLOAD_REQUEST(serviceModule), tempDB, serviceModule.getDirectoryPath(), extraParts)) {
FLog.d("Failed to upload database");
return;
}
}
示例7: postForm
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
public VerificationItems postForm(final Map<String, String> formParamValueMap, final String endpoint, final String boundary){
final HttpPost httpPost = new HttpPost(endpoint);
httpPost.setHeader(MultipartController.VERIFICATION_CONTROL_HEADER_NAME, MultipartController.VERIFICATION_CONTROL_FORM);
try {
for (Map.Entry<String, String> param : formParamValueMap.entrySet()) {
HttpEntity httpEntity = MultipartEntityBuilder
.create()
.setBoundary(boundary)
.setContentType(ContentType.MULTIPART_FORM_DATA)
//.addPart(FormBodyPartBuilder.create().addField(param.getKey(), param.getValue()).build())
.addPart(param.getKey(), new StringBody(param.getValue()))
.build();
httpPost.setEntity(httpEntity);
}
}catch (Exception e){
throw new IllegalStateException("Error preparing the post request", e);
}
return post(httpPost);
}
示例8: testStringBody
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
@Test
public void testStringBody() throws Exception {
final StringBody b1 = new StringBody("text", ContentType.DEFAULT_TEXT);
Assert.assertEquals(4, b1.getContentLength());
Assert.assertEquals("ISO-8859-1", b1.getCharset());
Assert.assertNull(b1.getFilename());
Assert.assertEquals("text/plain", b1.getMimeType());
Assert.assertEquals("text", b1.getMediaType());
Assert.assertEquals("plain", b1.getSubType());
Assert.assertEquals(MIME.ENC_8BIT, b1.getTransferEncoding());
final StringBody b2 = new StringBody("more text",
ContentType.create("text/other", MIME.DEFAULT_CHARSET));
Assert.assertEquals(9, b2.getContentLength());
Assert.assertEquals(MIME.DEFAULT_CHARSET.name(), b2.getCharset());
Assert.assertNull(b2.getFilename());
Assert.assertEquals("text/other", b2.getMimeType());
Assert.assertEquals("text", b2.getMediaType());
Assert.assertEquals("other", b2.getSubType());
Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
}
示例9: testBuildBodyPartBasics
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
@Test
public void testBuildBodyPartBasics() throws Exception {
final StringBody stringBody = new StringBody("stuff", ContentType.TEXT_PLAIN);
final FormBodyPart bodyPart = FormBodyPartBuilder.create()
.setName("blah")
.setBody(stringBody)
.build();
Assert.assertNotNull(bodyPart);
Assert.assertEquals("blah", bodyPart.getName());
Assert.assertEquals(stringBody, bodyPart.getBody());
final Header header = bodyPart.getHeader();
Assert.assertNotNull(header);
assertFields(Arrays.asList(
new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1"),
new MinimalField("Content-Transfer-Encoding", "8bit")),
header.getFields());
}
示例10: encodePOSTUrl
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
public static MultipartEntity encodePOSTUrl(MultipartEntity mEntity,
Bundle parameters) {
if (parameters != null && parameters.size() > 0) {
boolean first = true;
for (String key : parameters.keySet()) {
if (key != null) {
if (first) {
first = false;
}
String value = "";
Object object = parameters.get(key);
if (object != null) {
value = String.valueOf(object);
}
try {
mEntity.addPart(key, new StringBody(value));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return mEntity;
}
示例11: editWikiPage
import org.apache.http.entity.mime.content.StringBody; //导入依赖的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();
}
}
示例12: fileUpload
import org.apache.http.entity.mime.content.StringBody; //导入依赖的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");
}
}
示例13: apiUpload
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
/**
* Upload with <a href="http://www.sockshare.com/apidocs.php">API</a>.
*/
private void apiUpload() throws UnsupportedEncodingException, IOException, Exception{
uploading();
ContentBody cbFile = createMonitoredFileBody();
NUHttpPost httppost = new NUHttpPost(apiURL);
MultipartEntity mpEntity = new MultipartEntity();
mpEntity.addPart("file", cbFile);
mpEntity.addPart("user", new StringBody(sockShareAccount.username));
mpEntity.addPart("password", new StringBody(sockShareAccount.password));
httppost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httppost);
String reqResponse = EntityUtils.toString(response.getEntity());
//NULogger.getLogger().info(reqResponse);
if(reqResponse.contains("File Uploaded Successfully")){
gettingLink();
downURL = StringUtils.stringBetweenTwoStrings(reqResponse, "<link>", "</link>");
}
else{
//Handle the errors
status = UploadStatus.GETTINGERRORS;
throw new Exception(StringUtils.stringBetweenTwoStrings(reqResponse, "<message>", "</message>"));
}
}
示例14: fileUpload
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
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();
}
示例15: postJob
import org.apache.http.entity.mime.content.StringBody; //导入依赖的package包/类
/**
* Submit an application bundle to execute as a job.
*/
protected JsonObject postJob(CloseableHttpClient httpClient,
JsonObject service, File bundle, JsonObject jobConfigOverlay)
throws IOException {
String url = getJobSubmitUrl(httpClient, bundle);
HttpPost postJobWithConfig = new HttpPost(url);
postJobWithConfig.addHeader(AUTH.WWW_AUTH_RESP, getAuthorization());
FileBody bundleBody = new FileBody(bundle, ContentType.APPLICATION_OCTET_STREAM);
StringBody configBody = new StringBody(jobConfigOverlay.toString(), ContentType.APPLICATION_JSON);
HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("sab", bundleBody)
.addPart(DeployKeys.JOB_CONFIG_OVERLAYS, configBody).build();
postJobWithConfig.setEntity(reqEntity);
JsonObject jsonResponse = StreamsRestUtils.getGsonResponse(httpClient, postJobWithConfig);
RemoteContext.REMOTE_LOGGER.info("Streaming Analytics service (" + getName() + "): submit job response:" + jsonResponse.toString());
return jsonResponse;
}