【问题标题】:how to send request payload in json data using post method如何使用 post 方法在 json 数据中发送请求有效负载
【发布时间】:2016-11-28 13:10:28
【问题描述】:
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;行:1,列:1]

【问题讨论】:

    标签: java web-services http-post


    【解决方案1】:

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

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

    我试了几次,效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-07
      • 2020-04-28
      • 1970-01-01
      • 2018-07-22
      • 2013-04-17
      相关资源
      最近更新 更多