[Java] HttpConnections

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

[Java] HttpConnections

Post by terminus on Wed Apr 23, 2008 12:42 pm
([msg=1091]see [Java] HttpConnections[/msg])

Ever need to connect to or login to a web site through a java application? Java offers some classes for handling http traffic in the java.net package. However, writing usable code using these classes takes a lot of lines of code, a lot of time, a lot of beer, and usually ends up in code that is less functional that you would like. How do we get around all this pain and still get a lot of beer? Here is the solution:

Jakarata Commons HttpClient
http://hc.apache.org/httpclient-3.x/

HttpClient provides relatively easy to use classes for handeling Http communications. Simply download the tarball from the httpclient web site and you can be up and running in a matter of minutes. One way to go about this would be to put the java archive of all of the httpclient classes into your classpath. This can be placed into a location that is already recognized in the system wide $CLASSPATH or you can include the java archive file in the compile time classpath of your application.

An easy way to do this using Netbeans is to create a new java class library. In the projects tab on the left side of Netbeans the project should be listed. Right click on the project name and select Properties. Select Libraries. Select the tab Compile. Click Add Jar/Folder and browse for and select the commons java archive file. Finally, import any Package+Classes that your classes may need to call.

The HttpClient web site provides some excellent tutorials, sample code, and documentation to help an intermediate level Java programmer get well on their way to establishing many connections throughout the interwebs! Have fun.
terminus
New User
New User
 
Posts: 45
Joined: Mon Apr 14, 2008 9:10 am
Blog: View Blog (0)


Re: [Java] HttpConnections

Post by Inferno96 on Wed Apr 23, 2008 2:10 pm
([msg=1098]see Re: [Java] HttpConnections[/msg])

I can also attest that this set of classes works great. I don't program in java that often, but whenever I used to do html stuff in java, this was the package to use.
Inferno96
New User
New User
 
Posts: 27
Joined: Fri Apr 18, 2008 3:06 am
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron