• Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!