[英]How to properly send a multipart/form-data using an http GET request in jmeter
我有一個Apache服務器,正在嘗試使用JMeter進行負載測試。 有一種情況會導致我們的服務器在收到某些類型的請求時崩潰。 其中之一是帶有附件的GET請求。 如果我使用curl測試連接,效果很好。 這是我正在使用的示例卷曲字符串:
$ 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"
這是我在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)
在服務器端,日志顯示了一個有效的請求。
但是,當我嘗試使用JMeter發出相同的請求時。 它不起作用,服務器說:
java.io.IOException: Posted content type isn't multipart/form-data
當我查看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
請注意,從WireShark進行查看時,JMeter請求中缺少curl請求中的“(application / octet-stream)”。
我嘗試了MIMEType的每個變體(mime_multipart,multipart / form-data等),我認為這是沒有意義的。 我還嘗試了我能想到的每種內容編碼(應用程序/八位字節流,應用程序/二進制等),但似乎無濟於事。 附件永遠不會到達服務器。 我對如何進行感到困惑。
我還嘗試使用JMeter HTTIP記錄器/ HTTP代理來捕獲curl請求。 但是,它似乎無法正確處理我的代碼。 當我通過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"
該請求未能正確處理,這使我認為Recorder無法正確處理此jsp代碼。 最終結果與常規JMeter調用相同,但WireShark Capture結束時沒有(應用程序/八位位組流)。 記錄器確實設法添加具有以下標頭的HTTP標頭管理器:
內容類型多部分/表單數據; boundary = ------------------------ 56e0b872879ebd54期望100繼續接受/用戶代理curl / 7.32.0
但是,缺少與請求一起添加的文件。
我完全困惑如何進行。 有人知道我在做什么錯嗎? 此功能在JMeter中不起作用嗎? 有人知道我可以作為參考的一個好例子嗎?
我已經在這里和Google上進行過多次搜索,但沒有提出與該問題匹配的任何內容。 任何幫助將不勝感激。
以下是我的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>
首先,閱讀此答案和整個討論,將會帶來一些上下文。 我想許多客戶端庫都可以實現為使用GET方法發送消息正文受到限制。 如果Apache HTTP Client庫具有此類限制,那么將描述您的問題。 因此,一般而言,我建議您對主體使用POST方法而不是GET。
如果這對您來說不可接受,則可以使用jmeter-plugins.org的RawRequest插件執行自由格式的TCP請求,該請求將通過WireShark TCP流獲得。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.