jmeter - Magento2 400 使用 Apache JMeter 获取产品的错误请求
问题描述
我正在尝试使用 JMeter 对 Magento 2 API 的结帐过程进行负载测试。我们预计有 1000 个并发用户。
以下 curl 命令可以正常工作:
curl -g -X GET "https:/oursite.com/rest/V1/products/25006A/" -H "Authorization: Bearer tm2yd2908exmy0ntoq9esvr5gqoh7upp"
但是,当我在 JMeter 的标头中将相同的 Authorization Bearer 放入相同的 URL 时,它不会返回 JSON。相反,它会抛出 400 Bad Request。我还需要哪些其他标题?
这是我的 JMeter 脚本:
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Get Products" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">${varDomain}</stringProp>
<stringProp name="HTTPSampler.port"></stringProp>
<stringProp name="HTTPSampler.protocol">https</stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">/rest/V1/products/25006A/</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
<stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
</HTTPSamplerProxy>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Authorization Bearer</stringProp>
<stringProp name="Header.value">${varToken}</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">content-type</stringProp>
<stringProp name="Header.value">application/json</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
</hashTree>
解决方案
从JMeter 5.1开始,可以从curl命令创建 JMeter 测试计划
- 从 JMeter 的主菜单中选择
Tools -> Import from cURL
使用以下命令:
curl "https:/oursite.com/rest/V1/products/25006A/" -H "Authorization: Bearer tm2yd2908exmy0ntoq9esvr5gqoh7upp"
就是这样,JMeter 将生成具有正确值的HTTP 请求采样器和HTTP 标头管理器
您的脚本的问题是标题名称应该是Authorization
,标题值应该是Bearer tm2yd2908exmy0ntoq9esvr5gqoh7upp
推荐阅读
- node.js - tor 用户代理如何变化?解决
- reactjs - 你如何防止在 React Router 中出现连续的 URL?
- c++ - 如何在 glfw 中 glutDisplayFunc、glutMainLoop?
- swift - USDZ 文件在 Xcode 中是黑色的
- python - 使用 pyautogui 单击屏幕键盘
- c++ - C++:OpenMP 并行循环内存泄漏
- javascript - 表行在 中不可见。如何在此表中实现搜索过滤器?
- jenkins - Jenkins 使用构建触发器时
- php - 将mysql返回的多行打印到php
- javascript - JavaScript:模拟带有值的点击