|
19 | 19 | import java.io.ByteArrayInputStream;
|
20 | 20 |
|
21 | 21 | import org.apache.http.HttpResponse;
|
22 |
| -import org.apache.http.client.HttpClient; |
23 | 22 | import org.apache.http.client.methods.HttpPost;
|
24 | 23 | import org.apache.http.entity.InputStreamEntity;
|
25 |
| -import org.apache.http.entity.StringEntity; |
26 |
| -import org.apache.http.impl.client.DefaultHttpClient; |
| 24 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 25 | +import org.apache.http.impl.client.HttpClientBuilder; |
27 | 26 |
|
28 | 27 | /**
|
29 | 28 | * @author tamtam180 - kirscheless at gmail.com
|
30 | 29 | *
|
31 | 30 | */
|
32 | 31 | public class PostChunkTest {
|
33 | 32 |
|
34 |
| - /** |
35 |
| - * @param args |
36 |
| - */ |
37 |
| - public static void main(String[] args) throws Exception { |
38 |
| - |
39 |
| - HttpClient client = new DefaultHttpClient(); |
40 |
| - |
41 |
| - HttpPost post = new HttpPost("http://arango-test-server:9999/_api/import?collection=test1&createCollection=true&type=documents"); |
42 |
| - //post.setEntity(new StringEntity("{\"xx\": \"123\"}{\"xx\": \"456\"}")); |
43 |
| - InputStreamEntity entity = new InputStreamEntity(new ByteArrayInputStream("{\"xx\": \"123\"}{\"xx\": \"456\"}".getBytes()), 26); |
44 |
| - entity.setChunked(true); |
45 |
| - post.setEntity(entity); |
46 |
| - |
47 |
| - HttpResponse res = client.execute(post); |
48 |
| - |
49 |
| - System.out.println(res.getStatusLine()); |
50 |
| - |
51 |
| - post.releaseConnection(); |
52 |
| - } |
| 33 | + /** |
| 34 | + * @param args |
| 35 | + */ |
| 36 | + public static void main(String[] args) throws Exception { |
| 37 | + |
| 38 | + HttpClientBuilder builder = HttpClientBuilder.create(); |
| 39 | + CloseableHttpClient client = builder.build(); |
| 40 | + |
| 41 | + HttpPost post = new HttpPost( |
| 42 | + "http://localhost:8529/_api/import?collection=test1&createCollection=true&type=documents"); |
| 43 | + // post.setEntity(new StringEntity("{\"xx\": \"123\"}{\"xx\": |
| 44 | + // \"456\"}")); |
| 45 | + InputStreamEntity entity = new InputStreamEntity( |
| 46 | + new ByteArrayInputStream("{\"xx\": \"123\"}{\"xx\": \"456\"}".getBytes()), 26); |
| 47 | + entity.setChunked(true); |
| 48 | + post.setEntity(entity); |
| 49 | + |
| 50 | + HttpResponse res = client.execute(post); |
| 51 | + |
| 52 | + System.out.println(res.getStatusLine()); |
| 53 | + |
| 54 | + post.releaseConnection(); |
| 55 | + } |
53 | 56 |
|
54 | 57 | }
|
0 commit comments