• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

HttpURLConnection  RSS feed

 
Greenhorn
Posts: 20
  • 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: 16084
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!