简体   繁体   English

如何在jmeter中使用http GET请求正确发送multipart / form-data

[英]How to properly send a multipart/form-data using an http GET request in jmeter

I have an Apache server that I am trying to load test using a JMeter. 我有一个Apache服务器,正在尝试使用JMeter进行负载测试。 There is a situation that causes our server to crash when it is receiving certain kinds of requests. 有一种情况会导致我们的服务器在收到某些类型的请求时崩溃。 One of these is a GET request with an attachment. 其中之一是带有附件的GET请求。 If I test the connection using curl it works fine. 如果我使用curl测试连接,效果很好。 Here is a sample curl string that I am using: 这是我正在使用的示例卷曲字符串:

$ curl -X GET --connect-timeout 5 -m 600 -Y 200 -y 60 -F filename="@archives_x2cok01241201_.tar.gz" "http://172.17.0.150:8080/ckmp-ivc/IFEDataOffload?tailid=efxdom06281201&type=t&version=DL_X_FS_20120607&checksum=908022653&tailname=DL000"

And this is what I see with WireShark: 这是我在WireShark中看到的:

13  2.567406    172.17.0.102    172.17.0.150    HTTP    GET /ckmp-ivc/IFEDataOffload?tailid=efxdom06281201&type=t&version=DL_X_FS_20120607&checksum=908022653&tailname=DL000 HTTP/1.1  (application/octet-stream)

On the serverside, the log shows me a valid request. 在服务器端,日志显示了一个有效的请求。

However, when I try to make the same request using JMeter. 但是,当我尝试使用JMeter发出相同的请求时。 It doesn't work and the server says that: 它不起作用,服务器说:

java.io.IOException: Posted content type isn't multipart/form-data

When I look at the JMeter connection inside WireShark I see: 当我查看WireShark中的JMeter连接时,我看到:

177 157.326959  172.17.0.102    172.17.0.150    HTTP    GET /ckmp-ivc/IFEDataOffload?tailid=efxdom02071201&type=t&version=DL_X_FS_201202&checksum=908022653&tailname=DL000 HTTP/1.1 

Notice that the "(application/octet-stream)" from the curl request is missing in the JMeter request when viewed from WireShark. 请注意,从WireShark进行查看时,JMeter请求中缺少curl请求中的“(application / octet-stream)”。

I have tried every variation of MIMEType (mime_multipart, multipart/form-data, etc) I can think of to no avial. 我尝试了MIMEType的每个变体(mime_multipart,multipart / form-data等),我认为这是没有意义的。 I have also tried every content encoding (application/octet-stream, application/binary, etc) I can think of but nothing seems to work. 我还尝试了我能想到的每种内容编码(应用程序/八位字节流,应用程序/二进制等),但似乎无济于事。 The attachment never makes it to the server. 附件永远不会到达服务器。 I am stumped on how to proceed. 我对如何进行感到困惑。

I have also tried to use JMeter HTTIP Recorder / HTTP Proxy to capture the curl request. 我还尝试使用JMeter HTTIP记录器/ HTTP代理来捕获curl请求。 However, it doesn't seem to handle my code correctly. 但是,它似乎无法正确处理我的代码。 When I run curl through the JMeter proxy such as by: 当我通过JMeter代理运行curl时,例如:

$ curl -x localhost:8080 -X GET --connect-timeout 5 -m 600 -Y 200 -y 60 -F filename="@archives_x2cok01241201_.tar.gz" "http://172.17.0.150:8080/ckmp-ivc/IFEDataOffload?tailid=efxdom06281201&type=t&version=DL_X_FS_20120607&checksum=908022653&tailname=DL000"

The request fails to go through properly which makes me think that the Recorder can't handle this jsp code properly. 该请求未能正确处理,这使我认为Recorder无法正确处理此jsp代码。 The end result is the same as the regular JMeter call with no (applicaiton/octet-stream) at the end of the WireShark Capture. 最终结果与常规JMeter调用相同,但WireShark Capture结束时没有(应用程序/八位位组流)。 The Recorder does manage to add an HTTP Header Manager with the following Headers: 记录器确实设法添加具有以下标头的HTTP标头管理器:

Content-Type multipart/form-data; 内容类型多部分/表单数据; boundary=------------------------56e0b872879ebd54 Expect 100-continue Accept / User-Agent curl/7.32.0 boundary = ------------------------ 56e0b872879ebd54期望100继续接受/用户代理curl / 7.32.0

However, the file to be added with the request is missing. 但是,缺少与请求一起添加的文件。

I am completely baffled on how to proceed. 我完全困惑如何进行。 Does anyone know what I am doing wrong? 有人知道我在做什么错吗? Does this functionality not work in JMeter? 此功能在JMeter中不起作用吗? Does anyone know of a good example that I can use as a reference? 有人知道我可以作为参考的一个好例子吗?

I have searched repeatedly here and on google but I am not coming up with anything that matches this question. 我已经在这里和Google上进行过多次搜索,但没有提出与该问题匹配的任何内容。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Below is my JMeter Test Plan: 以下是我的JMeter测试计划:

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.5" jmeter="2.10 r1533061">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group - Tails - Test" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">1</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1362651221000</longProp>
        <longProp name="ThreadGroup.end_time">1362651221000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" 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">172.17.0.150</stringProp>
          <stringProp name="HTTPSampler.port">8080</stringProp>
          <stringProp name="HTTPSampler.connect_timeout">30000</stringProp>
          <stringProp name="HTTPSampler.response_timeout">30000</stringProp>
          <stringProp name="HTTPSampler.protocol">http</stringProp>
          <stringProp name="HTTPSampler.contentEncoding"></stringProp>
          <stringProp name="HTTPSampler.path"></stringProp>
          <stringProp name="HTTPSampler.concurrentPool">4</stringProp>
        </ConfigTestElement>
        <hashTree/>
        <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSV Data Set Config" enabled="true">
          <stringProp name="filename">C:\Test\Tail_info_efx.csv</stringProp>
          <stringProp name="fileEncoding"></stringProp>
          <stringProp name="variableNames">tailid,ipaddress,version,checksum,keystring,confignum,adsuffix</stringProp>
          <stringProp name="delimiter">,</stringProp>
          <boolProp name="quotedData">true</boolProp>
          <boolProp name="recycle">true</boolProp>
          <boolProp name="stopThread">true</boolProp>
          <stringProp name="shareMode">shareMode.all</stringProp>
        </CSVDataSet>
        <hashTree/>
        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="IFEDataOffload - hardcoded" enabled="true">
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments">
              <elementProp name="tailid" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">efxdom02071201</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">tailid</stringProp>
              </elementProp>
              <elementProp name="type" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">t</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">type</stringProp>
              </elementProp>
              <elementProp name="version" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">DL_X_FS_201202</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">version</stringProp>
              </elementProp>
              <elementProp name="checksum" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">908022653</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">checksum</stringProp>
              </elementProp>
              <elementProp name="tailname" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">DL000</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">tailname</stringProp>
              </elementProp>
            </collectionProp>
          </elementProp>
          <stringProp name="HTTPSampler.domain"></stringProp>
          <stringProp name="HTTPSampler.port"></stringProp>
          <stringProp name="HTTPSampler.connect_timeout"></stringProp>
          <stringProp name="HTTPSampler.response_timeout"></stringProp>
          <stringProp name="HTTPSampler.protocol"></stringProp>
          <stringProp name="HTTPSampler.contentEncoding">multipart/form-data</stringProp>
          <stringProp name="HTTPSampler.path">/ckmp-ivc/IFEDataOffload</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.implementation">Java</stringProp>
          <elementProp name="HTTPsampler.Files" elementType="HTTPFileArgs">
            <collectionProp name="HTTPFileArgs.files">
              <elementProp name="C:\Test\archives_efxdom02071201_.tar.gz" elementType="HTTPFileArg">
                <stringProp name="File.path">C:\Test\archives_efxdom02071201_.tar.gz</stringProp>
                <stringProp name="File.paramname">filename</stringProp>
                <stringProp name="File.mimetype">mime_multipart</stringProp>
              </elementProp>
            </collectionProp>
          </elementProp>
          <boolProp name="HTTPSampler.monitor">false</boolProp>
          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
        </HTTPSamplerProxy>
        <hashTree/>
        <ResultCollector guiclass="TableVisualizer" testclass="ResultCollector" testname="View Results in Table" enabled="true">
          <boolProp name="ResultCollector.error_logging">false</boolProp>
          <objProp>
            <name>saveConfig</name>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>true</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
              <bytes>true</bytes>
            </value>
          </objProp>
          <stringProp name="filename">C:\Test\Results Table</stringProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

First of all, read this answer and the whole discussion, it will bring some context. 首先,阅读答案和整个讨论,将会带来一些上下文。 I suppose many client libraries may be implemented with restriction to send message body with GET method. 我想许多客户端库都可以实现为使用GET方法发送消息正文受到限制。 If Apache HTTP Client library have such restriction, then your issue is described. 如果Apache HTTP Client库具有此类限制,那么将描述您的问题。 So in general I'd suggest you to use POST method with body instead of GET. 因此,一般而言,我建议您对主体使用POST方法而不是GET。

If this is not acceptable for you, you may use RawRequest plugin from jmeter-plugins.org to perform a freeform TCP-request which you'll get via WireShark TCP stream. 如果这对您来说不可接受,则可以使用jmeter-plugins.org的RawRequest插件执行自由格式的TCP请求,该请求将通过WireShark TCP流获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 multipart/form-data 发送请求? - how do I send a request using multipart/form-data? 如何使用Apache-nifi的InvokeHttp处理器附加文件发送http POST multipart / form-data请求? - How to send an http POST multipart/form-data request with a file attached using Apache-nifi's InvokeHttp processor? 如何正确格式化Http multipart / form-data请求以将文件上传到服务器 - How to properly format Http multipart/form-data request to upload file to the server 使用 $http 发送带角度的 multipart/form-data 文件 - Send multipart/form-data files with angular using $http 如何使用 Java Http 客户端发送具有多部分/表单数据主体的 PUT 请求? - How to send a PUT request with multipart/form-data body with Java Http Client? 如何使用AngularJS $ http发送multipart / form-data - How to use AngularJS $http to send multipart/form-data 解析 `multipart/form-data` http 请求是如何工作的? - How does parsing the `multipart/form-data` http request work? 如何在 Http 请求中的 multiPart/form-data 中写入布尔参数 - how to Write a boolean parameter in multiPart/form-data in Http request HTTP multipart / form-data发送字符串数组 - HTTP multipart/form-data send an array of strings React-Native通过HTTP发送多部分/表单数据 - React-Native send multipart/form-data through HTTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM