本文整理了Java中org.apache.http.entity.mime.MultipartEntity.writeTo()
方法的一些代码示例,展示了MultipartEntity.writeTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultipartEntity.writeTo()
方法的具体详情如下:
包路径:org.apache.http.entity.mime.MultipartEntity
类名称:MultipartEntity
方法名:writeTo
暂无
代码示例来源:origin: stackoverflow.com
try
entity.writeTo(bos);
代码示例来源:origin: stackoverflow.com
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
FileBody fileBody = new FileBody(new File(fileName));
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT);
multipartEntity.addPart("file", fileBody);
connection.setRequestProperty("Content-Type", multipartEntity.getContentType().getValue());
OutputStream out = connection.getOutputStream();
try {
multipartEntity.writeTo(out);
} finally {
out.close();
}
int status = connection.getResponseCode();
...
代码示例来源:origin: labexp/osmtracker-android
@Override
public void writeTo(final OutputStream outstream) throws IOException {
super.writeTo(new CountingOutputStream(outstream, this.listener));
}
代码示例来源:origin: CPPAlien/DaVinci
@Override
public byte[] getBody() throws AuthFailureError
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
mEntity.writeTo(bos);
}
catch (IOException e)
{
VinciLog.e("IOException writing to ByteArrayOutputStream bos, building the multipart request.", e);
}
return bos.toByteArray();
}
代码示例来源:origin: stackoverflow.com
File f = new File(path);
BufferedOutputStream out = new BufferedOutputStream( socket.getOutputStream() );
String filename=path.substring(path.lastIndexOf("/")+1);
// create a multipart message
MultipartEntity multipartContent = new MultipartEntity();
// send the file inputstream as data
InputStreamBody isb = new InputStreamBody(new FileInputStream(f), "image/jpeg", filename);
// add key value pair. The key "imageFile" is arbitrary
multipartContent.addPart("imageFile", isb);
multipartContent.writeTo(out);
out.flush();
out.close();
代码示例来源:origin: stackoverflow.com
File f = new File(path);
BufferedOutputStream out = new BufferedOutputStream( socket.getOutputStream() );
String filename=path.substring(path.lastIndexOf("/")+1);
// create a multipart message
MultipartEntity multipartContent = new MultipartEntity();
// send the file inputstream as data
InputStreamBody isb = new InputStreamBody(new FileInputStream(f), "image/jpeg", filename);
// add key value pair. The key "imageFile" is arbitrary
multipartContent.addPart("imageFile", isb);
multipartContent.writeTo(out);
out.flush();
out.close();
代码示例来源:origin: stackoverflow.com
MultipartEntity reqEntity = new MultipartEntity();
// add your ContentBody fields as normal...
// Now, pull out the contents of everything you've added and set it as the payload
ByteArrayOutputStream bos = new ByteArrayOutputStream((int)reqEntity.getContentLength());
reqEntity.writeTo(bos);
oAuthReq.addPayload(bos.toByteArray());
// Finally, set the Content-type header (with the boundary marker):
Header contentType = reqEntity.getContentType();
oAuthReq.addHeader(contentType.getName(), contentType.getValue());
// Sign and send like normal:
service.signRequest(new Token(oAuthToken, oAuthSecret), oAuthReq);
Response oauthResp = oAuthReq.send();
代码示例来源:origin: com.atlassian.httpclient/atlassian-httpclient-apache-httpcomponents
@Override
public Entity build()
{
try
{
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
apacheMultipartEntity.writeTo(outputStream);
final InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
final Header header = apacheMultipartEntity.getContentType();
final Map<String, String> headers = Maps.newHashMap();
headers.put(header.getName(), header.getValue());
return new MultiPartEntity(headers, inputStream);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: stackoverflow.com
ServletResponse httpResponse = ctx.getResponse();
ResponseFacade rf = (ResponseFacade) httpResponse;
httpResponse.setCharacterEncoding("UTF-8");
httpResponse.setContentType("multipart/mixed");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "SEPERATOR_STRING",Charset.forName("UTF-8"));
entity.addPart("json", new StringBody(CMD + "#" + content, "text/plain", Charset.forName("UTF-8")));
entity.addPart("image", new ByteArrayBody(data, "image/jpeg", "file"));
httpResponse.setContentLength((int) entity.getContentLength());
entity.writeTo(httpResponse.getOutputStream());
ctx.complete();
代码示例来源:origin: stackoverflow.com
URL url = new URL(baseURL+"/projects/"+projectId+"/CSVUpload?authenticity_token="+URLEncoder.encode(authToken, "UTF-8"));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
MultipartEntity entity = new MultipartEntity();
entity.addPart("utf8", new StringBody("\u2713", "text/plain", Charset.forName("UTF-8")));
entity.addPart("csv", new FileBody(csvToUpload, "text/csv"));
connection.setRequestProperty("Content-Type", entity.getContentType().getValue());
OutputStream out = connection.getOutputStream();
try {
entity.writeTo(out);
} finally {
out.close();
}
connection.getResponseCode();
代码示例来源:origin: com.github.vatbub/VirustotalPublicV2.0
private void addMultiparts(List<MultiPartEntity> multiParts, HttpURLConnection conn) throws IOException {
MultipartEntity multipartEntity =
new MultipartEntity(HttpMultipartMode.STRICT);
for (MultiPartEntity part : multiParts) {
multipartEntity.addPart(part.getPartName(), part.getEntity());
}
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type",
multipartEntity.getContentType().getValue());
//try to write to the output stream of the connection
OutputStream outStream = conn.getOutputStream();
multipartEntity.writeTo(outStream);
outStream.close();
}
代码示例来源:origin: kdkanishka/Virustotal-Public-API-V2.0-Client
private void addMultiparts(List<MultiPartEntity> multiParts, HttpURLConnection conn) throws IOException {
MultipartEntity multipartEntity =
new MultipartEntity(HttpMultipartMode.STRICT);
for (MultiPartEntity part : multiParts) {
multipartEntity.addPart(part.getPartName(), part.getEntity());
}
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type",
multipartEntity.getContentType().getValue());
//try to write to the output stream of the connection
OutputStream outStream = conn.getOutputStream();
multipartEntity.writeTo(outStream);
outStream.close();
}
代码示例来源:origin: stackoverflow.com
entity.writeTo(httpcon.getOutputStream());
os.close();
httpcon.connect();
代码示例来源:origin: stackoverflow.com
conn.addRequestProperty(reqEntity.getContentType().getName(), reqEntity.getContentType().getValue());
OutputStream os = conn.getOutputStream();
reqEntity.writeTo(os);
os.close();
conn.connect();
代码示例来源:origin: stackoverflow.com
conn.addRequestProperty(reqEntity.getContentType().getName(), reqEntity.getContentType().getValue());
OutputStream os = conn.getOutputStream();
reqEntity.writeTo(os);
os.close();
conn.connect();
代码示例来源:origin: stackoverflow.com
/* You will have done this bit earlier to authorize the user
OAuthService service = new ServiceBuilder().provider(TwitterApi.SSL.class).apiKey("[YOUR API KEY]").apiSecret("[YOUR SECRET]").callback("twitter://callback").build();
Token accessToken = Do you oauth authorization as normal
*/
OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json");
MultipartEntity entity = new MultipartEntity();
try {
entity.addPart("status", new StringBody("insert vacuous statement here"));
entity.addPart("media", new FileBody(new File("/path/of/your/image/file")));
ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);
request.addPayload(out.toByteArray());
request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());
service.signRequest(accessToken, request);
Response response = request.send();
if (response.isSuccessful()) {
// you're all good
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
entity.writeTo(out);
代码示例来源:origin: stackoverflow.com
try
entity.writeTo(bos);
代码示例来源:origin: stackoverflow.com
try
entity.writeTo(bos);
代码示例来源:origin: stackoverflow.com
try
entity.writeTo(bos);
内容来源于网络,如有侵权,请联系作者删除!