Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON POST to a server never arriving
    primarykey
    data
    text
    <p>I have an issue posting some JSON to a web service built using Jersey REST. The data never seems to arrive at the server.</p> <p>The overall task flow is somewhat like this:</p> <p><em><strong>Javascript POST JSON -> Webserver -> webserver get JSON and print out</em></strong></p> <p>Here is the Javascript that is supposed to POST the JSON data to the server, with path <code>/posttest</code>:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { var name = "Tony"; $.post( '/posttest', function (data) { alert("sune " + data.name); }); }) &lt;/script&gt; </code></pre> <p>I have a webserver (Grizzly) running all these classes:</p> <p>This class uses JAX-RS API to process POST requests that consume JSON data:</p> <pre><code>@Path("/posttest") public class PostTest { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response doPost(StatusBean b) { System.out.println("---&gt; " + b.getName()); StatusBean statusBean = new StatusBean(); return Response.status(Response.Status.ACCEPTED).entity(statusBean).build(); } </code></pre> <p>Here is the definition of the bean that data will be serialized to and from:</p> <pre><code>@XmlRootElement public class StatusBean { private String name; public StatusBean() { } public String getName() { return name; } public void setName(String name) { this.name= name; } } </code></pre> <p>Here is the test client class that print out the data in the console</p> <pre><code>ClientConfig cc = new DefaultClientConfig(); Client c = Client.create(cc); WebResource r = c.resource("http://localhost:9998/posttest"); StatusBean post = r.type(MediaType.APPLICATION_JSON_TYPE).post(StatusBean.class, new StatusBean()); System.out.println("--&gt; " + post.getName()); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload