如何测试 Unirest Get Response

问题描述

我有以下 Http get 请求,它与其他 API 一起使用,我现在需要从 UNirest 框架使用

我原来的 Rest 调用如下

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? 感谢帮助

问候

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...