0

我从 swagger 导入的请求有问题。

我有一个看起来像的请求/m2m/fim/items?filter=(tags=DEVICE)&exclude=tags,objectClass,href,operations,attributes,metadata,factory&expand=properties&limit=20

使用 swagger 我可以测试它,如果我在 Postman 中导入它,它也可以工作。它给了我当前的请求:

curl -X GET \ 'http://xx.xx.xxx.xxx/m2m/fim/items?filter=(tags%3DDEVICE)&exclude=tags%2CobjectClass%2Chref%2Coperat...' \

我的 SOAP 请求看起来像

"GET /m2m/fim/items?filter=%28tags%3DDEVICE%29&exclude=tags%2CobjectClass%2Chref%2Coperations%2Cattributes%2Cmetadata%2Cfactory&expand=properties&limit=20 HTTP/1.1[\r][\n]"

看起来“过滤器”参数的括号已针对请求进行了转换(邮递员不会发生这种情况),然后我的请求失败了。

谁能告诉我可以使用哪种语法,这样括号就不会被解释?

谢谢你

编辑:在我的 HTTP 日志中,我可以看到“Accept-Encoding: gzip,deflate”,这不是我想要的。在邮递员中,我有标题 Accept: application/json.

我知道如何从首选项中删除我当前的标题,但我不知道如何设置想要的标题。有人知道吗?

解决方案但不完整。

我发现了问题所在,我需要一个标题Accept: application/json

现在我的问题是以一种简单的方式将它添加到我所有测试用例中的所有请求中(我有超过 400 个请求)

亚历克斯

4

1 回答 1

0

添加标题的几种方法:

  • 在请求本身中:选择标题选项卡并添加它

  • 在资源级别:在“项目”选项卡中选择资源。

在资源路径的右侧,选择参数选项卡,然后单击添加参数。

设置名称和值并选择样式为 HEADER。

这将在 SoapUI 选项卡中此资源下的所有请求上设置标头

  • 在项目级别,为了更新所有测试用例中的所有请求:

在项目选项卡中,在事件处理程序管理器中添加一个事件。使用以下内容添加 RequestFilter.filterRequest 事件:

def headers = request.requestHeaders headers.put( "Accept", "application/json" ) request.requestHeaders = headers

警告 !仅使用一次,否则将在每个请求的启动时添加标头

最后,我使用了以下 groovy 脚本:

` 导入 com.eviware.soapui.support.types.StringToStringMap

testRunner.testCase.testSuite.project.testSuites.each {

suite ->
suite.getValue().testCases.each
{
    q1->
    q1.getValue().testSteps.each
    {
        it->
        if (it.getValue().config.type.equals("restrequest"))
        {
            //Get the headers of the current teststep
            def headers = it.getValue().getHttpRequest().getRequestHeaders()
            //log.info "headers = " + headers
            def list = []
            //Append the new header to the existing list
            list.add("application/json")
            log.info "list = " + list
            headers["Accept"] = list;
            //Set the updated header list
            it.getValue().getHttpRequest().setRequestHeaders(headers)
        }
    }
}

}
`

虽然我认为必须有一种方法可以使之前的解决方案一次性完成(但我在 groovy 方面不够熟练,无法找到它)

于 2018-01-24T14:21:34.380 回答