1

I'm desperate to find answer myself so I need external help.

Need a java code, which done exactly this: curl --data "username=&password=&submit=Login" -v

This is POST request to URL with data, which returns HEADERs, both sent and received.

Please advise! Thanks in advance!

vve1der
  • 60
  • 5
  • java.lang.Runtime.exec("curl .....")? See e.g., http://stackoverflow.com/questions/792024/how-to-execute-system-commands-linux-bsd-using-java – drRobertz Jan 19 '15 at 12:52
  • Do you mean you want to do the same in java. Or you really want java to run curl? – weston Jan 19 '15 at 12:53
  • Are you actually wanting to use curl from java or are you just wanting to know how to accomplish equivalent functionality within java? – Brett Okken Jan 19 '15 at 12:53
  • Did you try googling even once? I just googled "java curl example" and the first few links were stackoverflow question about this same topic. – forgivenson Jan 19 '15 at 12:53
  • In long term, yes! I need Java equivalent code. But now running from console is enough. Thanks to all of you for your interest to problem! – vve1der Jan 19 '15 at 13:05

1 Answers1

-2

Try this:

Process p = Runtime.getRuntime().exec( //
    new String[] { //
    //
      "curl", //
      "--data", //
      "username=&password=&submit=Login" //
});

This below will call the curl tool and passing it the following parameters: username=&password=&submit=Login.

Stephan
  • 41,764
  • 65
  • 238
  • 329
  • Should it print to console or I have to add this code? I'm sorry for dumb question, but I'm no Java developer but have to quickly fix Java application... – vve1der Jan 19 '15 at 12:55
  • I've made it with this answer: http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program – vve1der Jan 19 '15 at 12:58
  • You can ask curl to log its actions or you can redirect the curl output in a file... – Stephan Jan 19 '15 at 12:59