Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package easyhttp;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import java.util.UUID;
//import sun.net.www.protocol.http.HttpURLConnection;
/**
*
* @author admin
*/
public class EasyPost {
private DataOutputStream wr;
public static String CONTENT_TYPE = "Content-Type";
private String getBoundary() {
return UUID.randomUUID().toString();
}
Properties p;
public static void main(String[] args) throws FileNotFoundException {
// File f = new File("ecmUpload.xml");
File f = new File("upload.xml");
Properties p = new Properties();
try {
p.loadFromXML(new FileInputStream(f));
System.out.println(p.getProperty("data"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void ecmUploadFile(HttpURLConnection http) throws ProtocolException, IOException {
String boundary = UUID.randomUUID().toString();
byte[] boundaryBytes
= ("--" + boundary + "rn").getBytes(StandardCharsets.UTF_8);
byte[] finishBoundaryBytes
= ("--" + boundary + "--").getBytes(StandardCharsets.UTF_8);
String contentType = "multipart/form-data; charset=UTF-8; boundary=" + boundary;
http.setRequestMethod("POST"); // PUT is another valid option
http.setDoOutput(true);
http.setRequestProperty(CONTENT_TYPE, contentType);
try (OutputStream out = http.getOutputStream()) {
// Send our header (thx Algoman)
out.write(boundaryBytes);
sendField(out, "data", "");
// Send a seperator
out.write(boundaryBytes);
// Send our file
try (InputStream file = new FileInputStream("test.txt")) {
sendFile(out, "identification", file, "text.txt");
}
// Finish the request
out.write(finishBoundaryBytes);
}
}
private void sendFile(OutputStream out, String name, InputStream in, String fileName) throws IOException {
String o = "Content-Disposition: form-data; name="" + URLEncoder.encode(name, "UTF-8")
+ ""; filename="" + URLEncoder.encode(fileName, "UTF-8") + ""rnrn";
out.write(o.getBytes(StandardCharsets.UTF_8));
byte[] buffer = new byte[2048];
for (int n = 0; n >= 0; n = in.read(buffer)) {
out.write(buffer, 0, n);
}
out.write("rn".getBytes(StandardCharsets.UTF_8));
}
private void sendField(OutputStream out, String name, String field) throws IOException {
String o = "Content-Disposition: form-data; name=""
+ URLEncoder.encode(name, "UTF-8") + ""rnrn";
out.write(o.getBytes(StandardCharsets.UTF_8));
out.write(URLEncoder.encode(field, "UTF-8").getBytes(StandardCharsets.UTF_8));
out.write("rn".getBytes(StandardCharsets.UTF_8));
}
}
![]() |
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team