daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(String[] args) throws Exception {
  2.     sendPost();
  3. }
  4.  
  5. private static void sendPost() throws Exception {
  6.  
  7.     String url = "https://exampleSite.com";
  8.     URL obj = new URL(url);
  9.     HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  10.  
  11.     String account = "acc";
  12.     String password = "pass";
  13.  
  14.     //add reuqest header
  15.     con.setRequestMethod("POST");
  16.     con.setRequestProperty("Content-type", "text/xml");
  17.     String urlParameters = "account=" + account + "&password=" + password;
  18.  
  19.     // Send post request
  20.     con.setDoOutput(true);
  21.     DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  22.     wr.writeBytes(urlParameters);
  23.     wr.flush();
  24.     wr.close();
  25.  
  26.     int responseCode = con.getResponseCode();
  27.     System.out.println("nSending 'POST' request to URL : " + url);
  28.     System.out.println("Post parameters : " + urlParameters);
  29.     System.out.println("Response Code : " + responseCode);
  30.  
  31.     BufferedReader in = new BufferedReader(
  32.             new InputStreamReader(con.getInputStream()));
  33.     String inputLine;
  34.     StringBuffer response = new StringBuffer();
  35.  
  36.     while ((inputLine = in.readLine()) != null) {
  37.         response.append(inputLine);
  38.     }
  39.     in.close();
  40.  
  41.     //print result
  42.     System.out.println(response.toString());
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top