This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes apache httpclient 4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "apache httpclient 4" Watch "apache httpclient 4" New topic
Author

apache httpclient 4

Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
does anyone ever used apache httpclient 4? after a quick glance at the docs, I see that this is no different from java's standard HTTPServletRequest and HTTPServletResponse. What's the advantage of using this framework? thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
As its name implies, HttpClient is a *client* side library. HttpServletRequest/Response handle the server side. So, yes, there are plenty of use cases for it (like as a REST client).


Ping & DNS - my free Android networking tools app
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
I don't really follow. so where is this used? in coding the client side --> the jsp pages? or in the server side (servlets)?
if it's in the client side, does that mean the code will coexist with javascript codes?
thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
JSP is still a server side technology. No, this would be used in desktop or mobile apps that need to connect to a server (e.g., Android has that library built in). Or in a servlet on server A that needs to connect to server B.
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
normally it's JSP / html pages that issue requests and receive response from server's servlets. so let's say we have a form F (plain html and javascript). upon submission, servlet A begins processing F. in my understanding based on your explanation, if servlet A needs to delegate some of the work to server B, httpclient's APIs will be used in servlet A. is this correct? is it possible for httpclient's APIs to exist in HTML pages? or they can only exist in JSPs and servlets? as for desktop, what do you mean by desktop apps? are you referring to non web apps only? thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Hendra Kurniawan wrote:normally it's JSP / html pages that issue requests and receive response from server's servlets.


No, this is completely false. It's the browser which issues those requests and receives the responses, when you're talking about an ordinary web application. The HttpClient API is used to do the same sort of thing that the browser would be doing.
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
okay, let's say I have a webpage, and I need to get all the links in the webpage. Can I do that using httpclient? if possible, can anybody give simple code sample? thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
I'd use a library like HtmlUnit for that, since it understands a lot more about HTML that HttpClient does.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

We use HttpClient in Java to build a request then POST data to an external service.

WP
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
I have a task to parse a webpage. the webpage is static (the address URL won't change) and it has list of goods (the name, picture, URL to the manufacturer of the goods, price, etc). right now I have main class and Goods class. the questions are:
1. where to put the piece of code that parses the webpage and store it as Goods?
2. do I need interface or abstract class? or just put it in util class with those static methods?
 
Don't get me started about those stupid light bulbs.
 
subject: apache httpclient 4
 
Similar Threads
Calling a URL via HttpClient
Simulate real servlet container in unit test
sending https post request from servlet to another server
Requesting for web page through java program
HttpClient 4 and SOAP