问题
I have a curl request and i don't know how to transform it in jmeter :
curl -H application-id:my-app-id -H secret-key:my-secret-key -H Content-Type:"multipart/form-data" -H application-type:REST --form upload=@/logo.jpg -X POST -v http://localhost:8080/api/v1/files/Photos/logo.jpg
What is the best way of doing this?
回答1:
Option 1: Record the request
In JMeter:
- File -> Templates -> Recording -> Create
- Workbench -> HTTP(S) Test Script Recorder -> Start
In console:
curl -x localhost:8888 -H application-id:my-app-id ......
Option 2: Building Request Manually
Add HTTP Request sampler and configure it as follows:
- Server Name:
localhost
- Port Number:
8080
- Method:
POST
- Path:
/api/v1/files/Photos/logo.jpg
- Check
Use multipart/form-data
for POST - Switch to "Files Upload" tab
- Click "Add" and provide full path to logo.jpg file,
upload
as Parameter Name andimage.jpg
as MIME Type
- Server Name:
Add HTTP Header Manager and provide your headers names and values there
References:
- curl man page
- JMeter Proxy Step by Step
- How to Save ‘Loads’ of Time Using JMeter's Template Feature
回答2:
Simple .
- Create a Thread group .
RightClick on TestPlan --> Threads-->Thread Group
Add a HTTP Header manager add all Header entries
Right Click on Thread Group Created in Step1 --> Add-->ConfigElement-->HTTP Header Manager and add all[ -H application-id:my-app-id -H secret-key:my-secret-key -H Content-Type:"multipart/form-data" -H application-type:REST] Note: here you dont have to append -H
Add a HTTP sampler
Right Click on the ThreadGroup Created in Step1 --> Add-->Sampler-->HTTP Sampler provide ServerName or IP = local host and Port= 8080 and in Path =/api/v1/files/Photos/logo.jpg and method = post and There is add section for send files add accordingly
Add a Listener to verify the requests
Right Click on ThreadGroup created in Step1 --> Add-->Listener--> View result tree
By the end your Jmeter script should like
TestPlan
ThreadGroup[threads =1 loopcount=1]
HTTP HeaderManager
HTTPSAmpler
View Result Tree
Happy Testing . for more information http://jmeter.apache.org/usermanual/component_reference.html if it helps dont forget to click answered.
来源:https://stackoverflow.com/questions/37440639/testing-a-curl-request-with-jmeter