wood burning stoves*
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 Soft Skills this week in the Jobs Discussion 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
Bartender

Joined: Dec 16, 2010
Posts: 1066
    
  13

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".


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

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]
 
jQuery in Action, 2nd edition
 
subject: How does HttpURLConnection work when post data to server?