File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

apache httpclient 4

 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use HttpClient in Java to build a request then POST data to an external service.

WP
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic