java code to fake form POST?

D

D. Alvarado

Hi,
Does anyone know who I can fake submiting data via the POST method
in Java? This is code that I'm writing for a servlet, and the data is
too big such that I can just append it to the url I want to submit it
to.

Much thanks - Dave
 
T

Tor Iver Wilhelmsen

Does anyone know who I can fake submiting data via the POST
method in Java? This is code that I'm writing for a servlet, and the
data is too big such that I can just append it to the url I want to
submit it to.

You need to get the URLConnection's output stream and write to that
after you connect. To get the response, get the input stream right
after you finish writing. Preferrably you should put the data into a
StirngBuffer first and send a Content-Length header in the request as
well. And remember the right content-type for form data.
 
T

Tor Iver Wilhelmsen

ak said:
POST data must have Multipart format. See javax.mail.Mutlipart.

No, only if you want to simulate <input type=file>. You can perfectly
well send a POST with a body that looks just like the parameters would
look if you had used GET instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top