java - Issue with class cast during post request
问题描述
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
}
tiedd doing the post and faced this issue. Caught: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.String
Any other way to handle this issue?
解决方案
好像这条线
throw new RuntimeException(response.statusLine)
导致异常,不是吗?
尝试
throw new RuntimeException(response.statusLine.toString())
statusLine
不是 a String
,而是RuntimeException
需要构造函数的消息String
。
https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/StatusLine.html
推荐阅读
- python - 在 Django View 中构建 JSON 以循环遍历
- javascript - 如何专注于页面加载后加载的元素
- java - Sybase 和 Oracle DB 之间的数据比较
- php - 第二个查询在硬编码时有效,但在我用 POST 变量替换 WHERE 条件时无效
- java - Java - 无法摆脱 while 循环
- typescript - 在库中包含自定义打字稿声明文件
- javascript - 如何在 javascript 中自动执行指令
- sql - 访问查询:不包括指定的表达式
- python - 将 Python 脚本应用于 Blender 中的大量 .obj 文件
- google-app-engine - Google Cloud 上的权限被拒绝 appcfg.py