Created
December 18, 2019 12:48
-
-
Save AriffAzmi/40182152a1bfee6a23b3af17123c1bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadingPost { | |
private static final String POST_PARAMS = "TransactionType=SALE&PymtMethod=DD&ServiceID=POS&PaymentID=2d3d2287a9a4680518aa&OrderNumber=2d3d2287a9a4680518aa&Amount=300.00&CurrencyCode=MYR&HashValue=63c82ee2e64b093f73bfa42c1fe0a294fccc2506e7dcabfd4ad30abdece88148&HashValue2=9b50229fbf3d44f5bbc4002986e1dbef28339c9b1f61e155b00effc8f5d45213&TxnID=POS2d3d2287a9a4680518aa&IssuingBank=FPXDB2B&TxnStatus=0&AuthCode=123456&BankRefNo=1912080120490928&RespTime=2019-12-18 20:20:00&TxnMessage=Transaction Successfull"; | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) throws IOException{ | |
for(int i=0; i <= 2; i++) { | |
new Thread(() -> { | |
try { | |
sendPOST(); | |
} catch (IOException ex) { | |
Logger.getLogger(ThreadingPost.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
}).start(); | |
} | |
} | |
private static void sendPOST() throws IOException { | |
String POST_URL = "http://94.237.66.140/api/v1.0/update-payment-transaction"; | |
URL obj = new URL(POST_URL); | |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); | |
con.setRequestMethod("POST"); | |
// For POST only - START | |
con.setDoOutput(true); | |
OutputStream os = con.getOutputStream(); | |
os.write(POST_PARAMS.getBytes()); | |
os.flush(); | |
os.close(); | |
// For POST only - END | |
int responseCode = con.getResponseCode(); | |
System.out.println("POST Response Code :: " + responseCode); | |
if (responseCode == HttpURLConnection.HTTP_OK) { //success | |
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 | |
System.out.println(response.toString()); | |
} else { | |
System.out.println("POST request not worked \n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment