943,569 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 39951
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 11th, 2007
0

HTTP GET and POST REQUEST

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rinko is offline Offline
12 posts
since Apr 2007
Apr 11th, 2007
0

Re: HTTP GET and POST REQUEST

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Apr 11th, 2007
0

Re: HTTP GET and POST REQUEST

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rinko is offline Offline
12 posts
since Apr 2007
Apr 11th, 2007
0

Re: HTTP GET and POST REQUEST

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Apr 11th, 2007
0

Re: HTTP GET and POST REQUEST

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rinko is offline Offline
12 posts
since Apr 2007
Apr 11th, 2007
0

Re: HTTP GET and POST REQUEST

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Apr 11th, 2007
0

Re: HTTP GET and POST REQUEST

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Apr 12th, 2007
0

Re: HTTP GET and POST REQUEST

As the Input stream I get:
sun.net.www.protocol.http.
HttpURLConnection
$HttpInputStream@186c6b2
How can I get behind this 186c6b2 part?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rinko is offline Offline
12 posts
since Apr 2007
Apr 12th, 2007
0

Re: HTTP GET and POST REQUEST

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 8:59 am. Reason: typo
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Apr 26th, 2007
0

Re: HTTP GET and POST REQUEST

How can I go about when as an reply I get a byte stream that represents a gif file?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rinko is offline Offline
12 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Send SMS
Next Thread in Java Forum Timeline: madhavireddy wants a handout





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC