1
1
package org .javalite .http ;
2
2
3
+ import org .javalite .common .Inflector ;
4
+
3
5
import java .io .*;
4
6
import java .net .URLConnection ;
5
7
import java .util .ArrayList ;
6
8
import java .util .List ;
9
+ import java .util .UUID ;
7
10
8
11
/**
9
12
* Sets up a Multipart request to send multiple text fields as well as upload files.
10
13
*
11
14
* @author Igor Polevoy on 5/1/16.
12
15
*/
13
16
public class Multipart extends Request <Multipart > {
17
+
18
+ private static final String DASH = "------" ;
14
19
private static final String LINE_FEED = "\r \n " ;
15
20
16
21
private PrintWriter writer ;
17
22
private String boundary ;
18
23
private OutputStream outputStream ;
19
24
private List <FormField > formFields = new ArrayList <>();
20
25
26
+
27
+
21
28
/**
22
- * Contructor to make multipart requests
29
+ * Constructor to make multipart requests
30
+ *
23
31
* @param url URL to send request to
24
32
* @param connectTimeout connection timeout
25
33
* @param readTimeout read timeout
@@ -32,7 +40,7 @@ public Multipart(String url, int connectTimeout, int readTimeout) {
32
40
protected Multipart doConnect () {
33
41
34
42
try {
35
- boundary = "===" + System . currentTimeMillis () + "===" ;
43
+ boundary = "JavaLite-HTTP-" + UUID . randomUUID () ;
36
44
connection .setUseCaches (false );
37
45
connection .setDoOutput (true ); // indicates POST method
38
46
connection .setDoInput (true );
@@ -159,9 +167,12 @@ public Multipart file(String fieldName, String filePath ){
159
167
}
160
168
161
169
public static void main (String [] args ){
170
+
171
+ //use kitchensink
162
172
Multipart mp = Http .multipart ("http://localhost:8080/upload/save" )
163
173
.field ("name1" , "val1" )
164
174
.file ("file1" , "/home/igor/tmp/test.txt" );
165
- System .out .println (mp .text ());
175
+
176
+ System .out .println (mp .headers ());
166
177
}
167
178
}
0 commit comments