Skip to main content

cURL equivalent in JAVA



I am tasked with writing an authentication component for an open source JAVA app. We have an in-house authentication widget that uses https. I have some example php code that accesses the widget which uses cURL to handle the transfer.





My question is whether or not there is a port of cURL to JAVA, or better yet, what base package will get me close enough to handle the task?





Update :





This is in a nutshell, the code I would like to replicate in JAVA:







$cp = curl_init();

$my_url = "https://" . AUTH_SERVER . "/auth/authenticate.asp?pt1=$uname&pt2=$pass&pt4=full";

curl_setopt($cp, CURLOPT_URL, $my_url);

curl_setopt($cp, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($cp);

curl_close($cp);







Heath , I think you're on the right track, I think I'm going to end up using HttpsURLConnection and then picking out what I need from the response.


Comments

  1. Exception handling omitted:

    HttpURLConnection con = (HttpURLConnection) new URL("https://www.example.com").openConnection();
    con.setRequestMethod("POST");
    con.getOutputStream().write("LOGIN".getBytes("UTF-8"));
    con.getInputStream();

    ReplyDelete
  2. I'd use the Commons Http Client. There is a contrib class in the project that allows you to use ssl.

    We're using it and it's working well.

    Edit: Here's the SSL Guide

    ReplyDelete
  3. Try Apache Commons Net for network protocols. Free!

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?