如何使用post方法

时间:2016-11-28 13:10:28

标签: java web-services http-post

String pay= "["
            + "{"
            + "\"internalAssessmentResponseId\" : \"Mer\\/ccclsv__AC1B752E-D079-4BA9-AA4F-46E1F8DDC11F__3048\","
            + "\"responses\":["
            + "{"
            + "\"assessmentCreatedDate\":\"2016-11-25T11:35:54\","
            + "\"responseData\":[],"
            + "\"assessmentId\":\"943\","
            + "}"
            + "],"
            + "\"addtionalInformation\":[],"
            + "\"emailId\":\"lucky@me.com\","
            + "\"salesTeam\" :\"\","
            + "\"demographic\": {"
            + "},"
            + "\"repId\":\"AJMA-OG9OMQ\","
            + "\"assesseeId\":\"AGHA-2D0FVL\","
            + "\"assesseeType\":\"CONTACT\","
            + "\"typeOfResponse\":\"iPad\","
            + "\"userTimeZone\":\"a\""
            + "}"
            + "]";

    HttpClient httpclient = new HttpClient();
       PostMethod post = new PostMethod("http://signature");
       post.setRequestEntity(new StringRequestEntity(pay, "application/json", null));    
       httpclient.executeMethod(post);
       String jsonResponse = post.getResponseBodyAsString();
       jsonInsertRes = jsonResponse;
       System.out.println("Response in create==>"+jsonResponse);
      }
 catch (MalformedURLException e) 
  { 
      e.printStackTrace(); 
  }
  catch
  (IOException e)
  { 
  e.printStackTrace();
  }
       return jsonString.toString();        
    }

我得到的回答是错误的 无法构造org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput的实例,问题:抽象类型只能用其他类型信息实例化 在[来源:org.apache.catalina.connector.CoyoteInputStream@11ff00b3; line:1,column:1]

1 个答案:

答案 0 :(得分:0)

您可以尝试将JSON字符串作为字符串表单参数发送 然后在服务器上读取JSON字符串值并将字符串转换为Java对象(例如,说Message.java的对象)。

消息msgFromJSON = new ObjectMapper()。readValue(JSONString,Message.class);

我已经尝试过几次并且工作正常。