This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 828
    
  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: 60774
    
  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
how to send user credentials to a protected restful webservice
Guide on interfacing with JForum
How to programmatically login to JForum using Crowd Authentication
java.io.IOException: Server returned HTTP response code: 400 for URL:
reason for EOF exception?