|
@@ -0,0 +1,64 @@
|
|
1
|
+import java.io.BufferedReader;
|
|
2
|
+import java.io.IOException;
|
|
3
|
+import java.io.InputStream;
|
|
4
|
+import java.io.InputStreamReader;
|
|
5
|
+import java.util.ArrayList;
|
|
6
|
+import java.util.List;
|
|
7
|
+
|
|
8
|
+import org.apache.http.HttpEntity;
|
|
9
|
+import org.apache.http.HttpResponse;
|
|
10
|
+import org.apache.http.NameValuePair;
|
|
11
|
+import org.apache.http.client.HttpClient;
|
|
12
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
13
|
+import org.apache.http.client.methods.HttpPost;
|
|
14
|
+import org.apache.http.impl.client.HttpClients;
|
|
15
|
+import org.apache.http.message.BasicNameValuePair;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+public class TestServletPost{
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+ public TestServletPost(String url){
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+ InputStream instream = null;
|
|
25
|
+
|
|
26
|
+ try {
|
|
27
|
+ HttpClient httpclient = HttpClients.createDefault();
|
|
28
|
+ HttpPost httppost = new HttpPost(url);
|
|
29
|
+
|
|
30
|
+ // Request parameters and other properties.
|
|
31
|
+ List<NameValuePair> params = new ArrayList<NameValuePair>(2);
|
|
32
|
+ params.add(new BasicNameValuePair("method", "create_user"));
|
|
33
|
+ params.add(new BasicNameValuePair("name", "Gleisson"));
|
|
34
|
+ params.add(new BasicNameValuePair("bornDate", "1987/26/04"));
|
|
35
|
+ params.add(new BasicNameValuePair("sex", "m"));
|
|
36
|
+ params.add(new BasicNameValuePair("password", "SAUDE"));
|
|
37
|
+ params.add(new BasicNameValuePair("email", "sdrhgdsaj@sjhsdehj.com"));
|
|
38
|
+ httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
|
39
|
+
|
|
40
|
+ //Execute and get the response.
|
|
41
|
+ HttpResponse response = httpclient.execute(httppost);
|
|
42
|
+ HttpEntity entity = response.getEntity();
|
|
43
|
+
|
|
44
|
+ if (entity != null) {
|
|
45
|
+ instream = entity.getContent();
|
|
46
|
+ BufferedReader rd = new BufferedReader(new InputStreamReader(instream));
|
|
47
|
+ String line;
|
|
48
|
+ while((line = rd.readLine()) != null){
|
|
49
|
+ System.out.println(line);
|
|
50
|
+
|
|
51
|
+ }
|
|
52
|
+ }}
|
|
53
|
+ catch (Exception e){
|
|
54
|
+ }finally {
|
|
55
|
+ try {
|
|
56
|
+ instream.close();
|
|
57
|
+ } catch (IOException e) {
|
|
58
|
+ // TODO Auto-generated catch block
|
|
59
|
+ e.printStackTrace();
|
|
60
|
+ }
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+ }}
|