要求发布后上课的问题

时间:2018-09-15 15:52:59

标签: java rest groovy

    try {

        def contactId= "9999"
        def phoneNumber = 213213214
        def postObj = [PhoneNumber: phoneNumber,
                       ContactID  : contactId]

        def queryString = ["processAgainstExisting": true]

        def params = ["restVerb"     : "POST",
                      "postObj"      : postObj,

                      "path"         : "/contact/$contactId/PhoneNumber",
                      "query"        : queryString]

        def response = new PostRequest("Some url")
                .setParams(params)
                .execute()

        // check HttpResponse status code
        if (response.status != 200) {
            throw new RuntimeException(response.statusLine)
        }

} catch (Throwable e) {
    throw e
}

绑了这篇文章,并遇到了这个问题。 捕获:java.lang.ClassCastException:java.util.LinkedHashMap无法转换为java.lang.String

还有其他方法可以解决此问题吗?

1 个答案:

答案 0 :(得分:0)

似乎在线

throw new RuntimeException(response.statusLine)

引起异常,不是吗?

尝试

throw new RuntimeException(response.statusLine.toString())

statusLine不是String,但是RuntimeException需要向构造函数发送String消息。

https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/StatusLine.html