This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "HttpURLConnection" Watch "HttpURLConnection" New topic
Author

HttpURLConnection

ryan bohnert
Greenhorn

Joined: Feb 27, 2008
Posts: 15
I am working on a program that sends a request to a url using standalone java. The code below works, but I don't want a bufferedReader object back, all i want to do is make the connection to the url and add "name=ryan&age=28" or whatever i may need to tail end of the URL. I know i could add the name and age logic to the url creation, but i would really like to find out how to use the DataOutputStream to do this.

Any help ? Thanks

Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

There are two HTTP methods to make requests: GET and POST.

With GET, the parameters are appended to the URL, after a ? and separated by &. So if you want do this with a GET request, you would have to change the URL to: http://www.myurl.com?name=ryan&age=28

With a POST request, you send the data in the request body, which is what you seem to want to do. Here is an example of how to do a POST from Java: http://exampledepot.com/egs/java.net/Post.html


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: HttpURLConnection
 
Similar Threads
trying to open a connection to a secure server (unknown certificate)
HttpUrlConnection is not working
Modified Query on JProgressBar
trouble passing info from servlet to jsp
how to call servlet from java program