groovy - 如何测试 Unirest 获得响应
问题描述
我有以下 Http 获取请求,它与其他 API 一起使用,我现在需要从 UNirest 框架中使用
我原来的休息电话如下
def http = new HTTPBuilder(graph_base_user_url + "?")
http.request(GET) {
requestContentType = ContentType.JSON
//uri.query = [ $filter:"mail eq '$userEmail'"].toString()
uri.query=[$filter:"mail eq '$userEmail'"]
headers.'Authorization' = "Bearer " + AuthToken
response.success = { resp, json ->
//as the retunr json alue is an array collection we need to get the first element as we request all time one record from the filter
if (json.value){
_userId=json.value[0].id
}
else
_userId=-1 // user does not exist
}
// user ID not found : error 404
response.'404' = { resp ->
_userId = 'Not Found'
}
}
_userId
然后我需要将其转换为 UNirest 调用。为此,我从以下内容开始:
def result = post(graph_base_user_url + "?")
.headers("Authorization","Bearer " + AuthToken )
.queryString("$filter","mail eq '$userEmail'")
.asJson()
**response.success = { resp, json ->
if (json.value){
_userId=json.value[0].id
}
else
_userId=-1 // user does not exist
}
// user ID not found : error 404
response.'404' = { resp ->
_userId = 'Not Found'
}**
}
_userId
如何更改 Bold 中的代码以与 UNIRest 兼容?感谢帮助
问候
解决方案
推荐阅读
- r - 将子集的平均值作为参数传递给 ave() 中的函数
- javascript - Router.use() 需要中间件函数但得到一个字符串
- php - 如果声明在 var=EUR 的情况下回显图像不起作用
- postgresql - 如何解析 ZoneDateTime 格式?
- ag-grid - 从 ag-grid-enterprise 导入网格时出错
- javascript - 如何在 React/JavaScript 中将键值对迭代到 FormData Append
- kubernetes - Kubernetes中容器端口和目标端口的区别?
- java - forEach 中 JSONArray 上的迭代器?
- list - 从字典中的列表中删除元素
- json - 从 JSON 创建节点和关系(动态)