This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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
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
 
His brain is the size of a cherry pit! About the size of this ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!