Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. curl -u username:password https://example.com/xyz/abc
  2.  
  3. String username="myusername";
  4. String password="mypassword";
  5. String url="https://www.example.com/xyz/abc";
  6. String[] command = {"curl", "-u" ,"Accept:application/json", username, ":" , password , url};
  7. ProcessBuilder process = new ProcessBuilder(command);
  8. Process p;
  9. try
  10. {
  11. p = process.start();
  12. BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
  13. StringBuilder builder = new StringBuilder();
  14. String line = null;
  15. while ( (line = reader.readLine()) != null) {
  16. builder.append(line);
  17. builder.append(System.getProperty("line.separator"));
  18. }
  19. String result = builder.toString();
  20. System.out.print(result);
  21.  
  22. }
  23. catch (IOException e)
  24. { System.out.print("error");
  25. e.printStackTrace();
  26. }
  27.  
  28. String[] command = {"curl", "-u" ,"Accept:application/json", username, ":" , password , url};
  29.  
  30. String[] command = {"curl", "-H", "Accept:application/json", "-u", username+":"+password , url};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement