-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPOST.java
More file actions
44 lines (36 loc) · 1.14 KB
/
POST.java
File metadata and controls
44 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.panoskrt.HTTP;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class POST {
public void HTTP() {
}
public String postRequest(String URL, String parameters, String agent) {
String postResponse = null;
try {
URL obj = new URL(URL.toString());
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Request Header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", agent);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
// Post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(parameters);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) { response.append(inputLine); }
in.close();
postResponse = response.toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return postResponse;
}
}