0

I have a servlet that reads a JSON string from a POST. A third (PHP) party application posts a JSON string to the servlet which adds the data to a database, but something is going wrong.

I want to do some testing, and I want to have a simple servlet (or just a main java class) that posts a JSON string to the servlet. But I'm not really finding how to do this.

Any idea how to do this? Any tips where to start?

Thanks very much for any help!

Steven Filipowicz
  • 389
  • 2
  • 10
  • 25

3 Answers3

0

The Jakarta Commons HttpClient provides the sort of functionality you will need to do this.

http://hc.apache.org/httpclient-3.x/

you will be able to use it to construct a POST request and dispatch that to your servlet.

mcfinnigan
  • 11,442
  • 35
  • 28
0

You need not write code to achieve this, rather can use the simple Firefox plugin to do this

Plugin - https://addons.mozilla.org/en-US/firefox/addon/poster/

Point the url to your java servlet that needs to be tested,

Put application/json in content type text box,

Put the json data that you want to send in "Content to Send" section

Do not forget to click on "Post" at the end :)

Karthik Ananth
  • 211
  • 1
  • 8
0

Write a simple main class and post JSON. You could write out the post you are receiving from the PHP to a file then simply post that using URLConnection or Apache HTTPClient from main.

Something like this:

HTTP POST using JSON in Java

Community
  • 1
  • 1
chubbsondubs
  • 37,646
  • 24
  • 106
  • 138