Thứ Tư, 21 tháng 9, 2016
Tích hợp thẻ cào
HttpURLConnectionExample http = new HttpURLConnectionExample();
// Tao chu ky
String chuoiParam = accesskey=6fe7a9a25c4e30e731c0bc1d18e9da28&serial=123456789&pin=12345678&type=VTT&privatekey=7dbf0ee2739fa53d41b74424be99ec2c
String signature = MD5(chuoiParam);
http.sendPost(access_key, type, pin, serial, signature);
}
// HTTP POST request
privatevoid sendPost(String access_key, String type, String pin,
String serial, String signature) throws Exception {
String url = "http://sms.vn/card-charging-api
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// add reuqest header
con.setRequestMethod("POST");
String urlParameters = "accesskey="+access_key+"&type="+type+"&pin="+pin+"&serial="+serial+"&signature="+signature;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con
.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
Đăng ký:
Nhận xét (Atom)