User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 426,136 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,755 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 7529 | Replies: 10
Reply
Join Date: Apr 2007
Posts: 12
Reputation: rinko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rinko rinko is offline Offline
Newbie Poster

HTTP GET and POST REQUEST

  #1  
Apr 11th, 2007
Dear all I am currently trying to find a java source code with which either HTTP POST or GET request can be sent. Unfortunately I have run into bunch of snippets that I can not run. Is there anyone that can tell me where I can find complete source code for sending POST or GET request?
Thank you in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: HTTP GET and POST REQUEST

  #2  
Apr 11th, 2007
What are you talking about?

Look up HttpURLConnection in the API or HttpClient from apache. And, no, neither of these things will give you finished code to simply execute and do what you want. Nothing ever will.

Both of these are APIs, of which you can search and find tutorials for, but you need to use them in your coding in order to do what you want. Trust me, you can do both a Get and a Post with either of them.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: rinko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rinko rinko is offline Offline
Newbie Poster

Re: HTTP GET and POST REQUEST

  #3  
Apr 11th, 2007
Thank you for your help. I used HttpUrlConnection and I managed to establish the connection with a server. Now, I would like to see the content of the response. With getResponseCode and getResponseMessage I only get responses on my request but not the content. What class should be used in this case?
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,858
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: HTTP GET and POST REQUEST

  #4  
Apr 11th, 2007
If you are talking about reading the contents of the form submitted using the GET or POST method, try looking into getParameter(input_type_name) method of the request class.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: rinko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rinko rinko is offline Offline
Newbie Poster

Re: HTTP GET and POST REQUEST

  #5  
Apr 11th, 2007
I am talking about the contents of the response. What if response contains an image, XML file, or a hyperlink for example. How can I read these content elements?
Thanks
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,858
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: HTTP GET and POST REQUEST

  #6  
Apr 11th, 2007
You don't as such get the contents of the resopnse. Reponse in general is sent to the client -- what to do with it depends on the client, which is normally browser in our case. You can let the browser know you are sending an XML file or video by setting the content type of the response.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: HTTP GET and POST REQUEST

  #7  
Apr 11th, 2007
You need to call getInputStream(), to get the inputStream of the response (actually, in relation to the response it is an outputStream, but in relation to your Java Program it is an inputStream), then you can read that, but remember, it will be HTML, so any images will be found as IMG tags, then you then need to retrieve with another HttpURLConnection and its getInputStream.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: rinko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rinko rinko is offline Offline
Newbie Poster

Re: HTTP GET and POST REQUEST

  #8  
Apr 12th, 2007
As the Input stream I get:
sun.net.www.protocol.http.
HttpURLConnection
$HttpInputStream@186c6b2
How can I get behind this 186c6b2 part?
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: HTTP GET and POST REQUEST

  #9  
Apr 12th, 2007
Read the Sun I/O Tutorials to find out how you work with an InputStream.

An InputStream is NOT a String representation of the entire page contents. It is a "Stream" that you have to read byte by byte (although wrapping it in other objects, i.e. a BufferedReader, will allow you to read it line by line, rather than byte by byte). But that is too much to explain here, so please read the I/O Tutorials at Sun.

http://java.sun.com/docs/books/tutor.../io/index.html
Last edited by masijade : Apr 12th, 2007 at 7:59 am. Reason: typo
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: rinko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rinko rinko is offline Offline
Newbie Poster

Re: HTTP GET and POST REQUEST

  #10  
Apr 26th, 2007
How can I go about when as an reply I get a byte stream that represents a gif file?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 4:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC