Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes How does HttpURLConnection work when post data to server? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How does HttpURLConnection work when post data to server?" Watch "How does HttpURLConnection work when post data to server?" New topic
Author

How does HttpURLConnection work when post data to server?

lyj csu
Greenhorn

Joined: May 25, 2013
Posts: 1
I want to test HttpServletRequest.getParameter(), and post data with OutputStream from HttpURLConnection, my data is like this:



I get data in my servlet class:



the result is, I can only get part of data: "hello", so I want to find what happened when in HttpURLConnection ,but I even can't find the source code of
getOutputStream
in HttpURLConnection .

When I come to HttpClient, I can't get any value of the key:



Can anyone help me ? Or just tell me how to find the source code of getOutputStream in HttpURLConnection? Thank you.
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632
    
    7

lyj csu wrote:
the result is, I can only get part of data: "hello", so I want to find what happened when in HttpURLConnection ,but I even can't find the source code of


That's because "key=hello" is the complete, first parameter. The ampersand signifies the start of the second parameter. I think you are looking for "key=hello%20world".


"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

The value needs to be URL-encoded; otherwise, as J. pointed out, the & character is interpreted as a delimiter.

See URLEncoder


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does HttpURLConnection work when post data to server?
 
Similar Threads
Guide on interfacing with JForum
How to programmatically login to JForum using Crowd Authentication
how to send user credentials to a protected restful webservice
java.io.IOException: Server returned HTTP response code: 400 for URL:
reason for EOF exception?