如何使用更新文件的JMeter来使用HTTP PUT

时间:2016-06-14 10:52:31

标签: rest jmeter apache-httpclient-4.x put

我必须为上传文件的PUT(REST服务)请求进行负载测试。

我可以使用以下信息从Advanced Rest Client成功使用:

服务:

PUT http://localhost:8080/home/cmistest/app/documentservices/rest/nodes/upload/12178

接头:

Content-Type: multipart/form-data, Accept: application/json

响应:

{
  "UploadContentResponse": {
    "Id": 12179,
    "ContentUrl": "http://localhost:8080/home/cmistest/app/documentservices/rest/nodes/12179/content"
  }
}

我无法使用JMeter的PUT。

我可以看到JMeter File Upload with HTTP Put Method Not Working 但不确定需要设置哪些标头。

1 个答案:

答案 0 :(得分:1)

首先,我首先回顾Testing SOAP/REST Web Services Using JMeter该公司的网站对我来说非常有价值。

在测试计划级别添加以下配置元素:

HTTP Request Defaults
    Web Server Name:    localhost
    Port Number:        8080
    Protocol:           http
    Content Encoding:   utf8

在线程组中,添加此配置元素:

HTTP Header Manager
    Name:   Content-Type
    Value:  application/json

现在,如果你实际上正在创建你传递的json数据,我会通过RegEx对其进行参数化,然后可以在PUT请求中使用它。

CREATE HTTP Request
    Method:     POST
    Path:       /home/cmistest/app/documentservices/rest/nodes/create/12178
    Use multipart/form-data for POST: enabled
    Body Data:
    {
        "id": 0,
        "name": "Star Lord",
        "address": "123 Milky Way",

    }

    Regular Expression Extractor
        Name:           newWhateverId
        Apply To:       Main Sample Only
        Field to check: Body
        Reference Name: newWhateverId
        Regular Expression: \,"Id":(.+?)\,
        Template:       $1$
        Match No.:      1
        Default Value:  NONE

    Regular Expression Extractor
        Name:           newWhateverBody
        Apply To:       Main Sample Only
        Field to check: Body
        Reference Name: newWhateverBody
        Regular Expression: (?s)(^.*)
        Template:       $1$
        Match No.:      1
        Default Value:  NONE

然后在PUT HTTP请求中,您只需传入值:

PUT HTTP Request
    Method:     PUT
    Path:       /home/cmistest/app/documentservices/rest/nodes/upload/${newWhateverId}
    Body Data:
    {
        ${newWhateverBody}          
    }