import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class APITest { public static void main (String args[]) { String urlAPI = "https://masothue.vn/Ajax/Search"; String q = "8055549499"; //Replace with your client ID String type = "personal"; //Replace with your client Secret try { URL url = new URL(urlAPI); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "multipart/form-data"); String input = "{\"q\": \"" + q + "\",\"type\":\"" + type +"\"} "; System.out.println(input); OutputStream outputStream = connection.getOutputStream(); outputStream.write(input.getBytes()); outputStream.flush(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new RuntimeException("Please check your inputs : HTTP error code : "+ connection.getResponseCode()); } BufferedReader bufferedReader; bufferedReader = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; System.out.println("Output from MA SO THUE .... \n"); while ((output = bufferedReader.readLine()) != null) { System.out.println(output); } connection.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }