2016-06-14 89 views
1

我必须对上传文件的PUT(REST服务)请求进行负载测试。如何使用更新文件的JMeter使用HTTP PUT

我能够从高级REST客户端具有以下信息成功消耗:

服务:

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

首先,我首先回顾一下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}   
    }