title: Jersey POST request from Java Application Client
body: <p>I have a Java Application Client and I want to make a post request to server .
  This is my SecretaryResource POST service </p>
  
  <pre><code>@POST
   @Consumes(MediaType.APPLICATION_XML)
   public Secretary addSecretary(Secretary sec)
   {
        return secService.addSecretary(sec);
  
   }
  </code></pre>
  
  <p>This is my client method :</p>
  
  <pre><code>public boolean addSecretary()
      {
         Client client = ClientBuilder.newClient();
          WebTarget target = client.target("http://localhost:8080/ClinicManager/webapi/secretary");
  
  Form form = new Form();
  form.param("id","hardcoded");
  form.param("password","hardcoded");
  form.param("name", "hardcodedname");
  
  Secretary bean =
  target.request(MediaType.APPLICATION_XML)
     .post(Entity.entity(form,MediaType.APPLICATION_FORM_URLENCODED_TYPE),
           Secretary.class);
  
  
  return true;
  
  
      }
  </code></pre>
  
  <p>And I get this exception </p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
  at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1017)
  at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:816)
  at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
  at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:700)
  at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
  at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
  at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
  at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
  at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)
  at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
  at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
  at clinicmanagerclient.controller.SecretaryDOM.addSecretary(SecretaryDOM.java:104)
  at clinicmanagerclient.view.SecretaryCRUD.jButton2ActionPerformed(SecretaryCRUD.java:129)
  at clinicmanagerclient.view.SecretaryCRUD.access$100(SecretaryCRUD.java:21)
  at clinicmanagerclient.view.SecretaryCRUD$3.actionPerformed(SecretaryCRUD.java:79)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
  at java.awt.Component.processMouseEvent(Component.java:6525)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
  at java.awt.Component.processEvent(Component.java:6290)
  at java.awt.Container.processEvent(Container.java:2234)
  at java.awt.Component.dispatchEventImpl(Component.java:4881)
  at java.awt.Container.dispatchEventImpl(Container.java:2292)
  at java.awt.Component.dispatchEvent(Component.java:4703)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
  at java.awt.Container.dispatchEventImpl(Container.java:2278)
  at java.awt.Window.dispatchEventImpl(Window.java:2739)
  at java.awt.Component.dispatchEvent(Component.java:4703)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
  at java.awt.EventQueue.access$400(EventQueue.java:97)
  at java.awt.EventQueue$3.run(EventQueue.java:697)
  at java.awt.EventQueue$3.run(EventQueue.java:691)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
  at java.awt.EventQueue$4.run(EventQueue.java:719)
  at java.awt.EventQueue$4.run(EventQueue.java:717)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  </code></pre>
  
  <p>I also tried in this way . Still don't work :</p>
  
  <pre><code> Client client = ClientBuilder.newClient( new ClientConfig().register( LoggingFilter.class ) );
  WebTarget webTarget = client.target("http://localhost:8080").path("/ClinicManager/webapi/secretary");
  
  Secretary sec = new Secretary();
  sec.setId(100);
  sec.setName("David Feezor");
  sec.setPassword("parola");
  
  Invocation.Builder invocationBuilder =  webTarget.request(MediaType.APPLICATION_JSON);
  Response response = invocationBuilder.post(Entity.entity(sec, MediaType.APPLICATION_JSON));
  </code></pre>
  
  <p>I tested the POST service with Postman and it works fine . The wrong part is from the client side . Please help me !</p>