This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am not sure if this is the correct place to post this, please feel free if the moderators can find a better place for this post. I have a general question regarding using curl (http://curl.haxx.se/) with Java. I have a web-application running in tomcat, based on certain actions in my web-applications I need to write a java code which would trigger curl. Curl would then query a third-party application and return an XML/JSON.
this has to be read by me and return appropriate response to the user.
Can this be done ? I see that curl has a binary distribution for Linux, once I download it (http://curl.haxx.se/download.html) how do I call this from my java web-app.
Seems to me that calling out to a command line tool to do this is the worst possible approach.
But it looks as if there's a Java binding -- you might want to check that out.
Joined: Sep 12, 2009
Looking at all the cases/possibilities, i have opted to do this using httpclient or urlconnection class. I have not written the complete code but have just manage to write which would get us started atleast..
If I had used curl - I would have to write the following.
this would have returned me an output in XML
with httpclient i think this could be done with something like this...
With this, I have only taken care of the parameters, how to I pass the username and password with this ? any help ?
Also by default, with CURL the username and password is encoded with base64 internally, that would mean now I have to take care of 2 things
1. Encode the Username and password with base64 format
2. Accommodate the username and password in httpclient call.
Joined: Sep 12, 2009
Ok, I was able to add authentication and encoding to the code, as of now the code looks something like this.
Using this I get the return value for rCode as "406". Why am I receiving a response which is "Not Acceptable" Anything which would help me debug better and fix this.