protected String sendPost String uri String data URL url null HttpsURL

 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
protected String sendPost(String uri, String data) {
URL url = null;
HttpsURLConnection conn = null;
DataOutputStream output = null;
DataInputStream input = null;
StringBuilder resp = new StringBuilder();
try {
url = new URL(uri);
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
try {
conn = (HttpsURLConnection) url.openConnection();
} catch (IOException ex) {
ex.printStackTrace();
}
try {
conn.setRequestMethod("POST");
} catch (ProtocolException ex) {
ex.printStackTrace();
}
conn.setRequestProperty("Content-length", String.valueOf(data.length()));
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent", "CVV Checker");
conn.setDoOutput(true);
conn.setDoInput(true);
try {
output = new DataOutputStream(conn.getOutputStream());
output.writeBytes(data);
output.close();
input = new DataInputStream(conn.getInputStream());
for(int c = input.read(); c != -1; c = input.read())
resp.append((char) c);
input.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return resp.toString();
}