【问题标题】:Issue with POST method in JIRA REST APIJIRA REST API 中的 POST 方法问题
【发布时间】:2016-10-28 15:37:36
【问题描述】:

我需要使用 java REST API 将用户添加到 JIRA 中的组。我需要使用组名作为查询参数和用户名作为有效负载进行 POST。我正在使用相同的 Spring RestOperations。这是我的代码:

JSONObject jsonObject = new JSONObject();
jsonObject.put("username", abc@cs.com);

Group group = restOperations.exchange(
                "https://cs.jira.com/jira/rest/api/2/group/user?groupname=jira-users",
                HttpMethod.POST,
                new HttpEntity<>(jsonObject, getAuthorizedHttpHeaders(user, pass)),
                Group.class).getBody();

我收到以下异常:

org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [org.codehaus.jettison.json.JSONObject] and content type [application/json;charset=UTF-8]

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: json post jira-rest-api


    【解决方案1】:

    这里有两个错误... 有效载荷无效。您需要放置一个以 name 为键的 JSON 对象:

    {"name":"abc@cs.com"}
    

    应该是:

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", abc@cs.com);
    

    如此处所述:https://docs.atlassian.com/jira/REST/cloud/#api/2/group-addUserToGroup

    但是,您当前遇到的异常是由于您将 JSONObject 传递给您的 HttpEntity 造成的。 JSONObject 不存在映射消息转换器。

    应该是:

    new HttpEntity<String>(jsonObject.toString(), getAuthorizedHttpHeaders(user, pass))
    

    【讨论】:

      猜你喜欢
      • 2017-01-23
      • 1970-01-01
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      相关资源
      最近更新 更多