【问题标题】:How to deal with 401 Unauthorized response i Jmeter V3.0 or lower?Jmeter V3.0或更低版本如何处理401 Unauthorized response?
【发布时间】:2017-07-17 12:57:33
【问题描述】:

我正在尝试使用 admin:admin 作为凭据登录 the-internet.herokuapp.com/basic_auth。

我正在使用 Jmeter v3.0,我添加了 HTTP 授权管理器、Cookie 管理器,并在标头管理器中添加了名称和值,如图所示,但我仍然收到 401 未经授权的响应。

我在 Jmeter v3.1 及其工作的不同系统中尝试了同样的事情。

有人知道如何解决 Jmeter v3.0 或更低版本的问题吗?

【问题讨论】:

    标签: jmeter http-status-code-401 http-authentication


    【解决方案1】:

    我无法使用 JMeter 3.0 重现您的问题,并且除了 HTTP 请求之外仅添加了 HTTP Authorization Manager:

    这是一个完整的Test Plan,以防万一:

    <?xml version="1.0" encoding="UTF-8"?>
    <jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0 r1743807">
    <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" 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">1500191430000</longProp>
          <longProp name="ThreadGroup.end_time">1500191430000</longProp>
          <boolProp name="ThreadGroup.scheduler">false</boolProp>
          <stringProp name="ThreadGroup.duration"></stringProp>
          <stringProp name="ThreadGroup.delay"></stringProp>
        </ThreadGroup>
        <hashTree>
          <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" 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">the-internet.herokuapp.com</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"></stringProp>
            <stringProp name="HTTPSampler.path">/basic_auth</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>
            <boolProp name="HTTPSampler.monitor">false</boolProp>
            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
          </HTTPSamplerProxy>
          <hashTree>
            <AuthManager guiclass="AuthPanel" testclass="AuthManager" testname="HTTP Authorization Manager" enabled="true">
              <collectionProp name="AuthManager.auth_list">
                <elementProp name="" elementType="Authorization">
                  <stringProp name="Authorization.url"></stringProp>
                  <stringProp name="Authorization.username">admin</stringProp>
                  <stringProp name="Authorization.password">admin</stringProp>
                  <stringProp name="Authorization.domain"></stringProp>
                  <stringProp name="Authorization.realm"></stringProp>
                </elementProp>
              </collectionProp>
            </AuthManager>
            <hashTree/>
          </hashTree>
          <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" 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>false</xml>
                <fieldNames>true</fieldNames>
                <responseHeaders>false</responseHeaders>
                <requestHeaders>false</requestHeaders>
                <responseDataOnError>false</responseDataOnError>
                <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
                <assertionsResultsToSave>0</assertionsResultsToSave>
                <bytes>true</bytes>
                <threadCounts>true</threadCounts>
                <idleTime>true</idleTime>
              </value>
            </objProp>
            <stringProp name="filename"></stringProp>
          </ResultCollector>
          <hashTree/>
        </hashTree>
      </hashTree>
    </hashTree>
    </jmeterTestPlan>
    

    我建议从 HTTP 标头管理器中删除您的 Authorization 标头以防万一。

    有关在 JMeter 测试中绕过基本访问身份验证的更多详细信息,请参阅 How to Use HTTP Basic Authentication in JMeter 文章。


    强烈建议尽可能使用最新的 JMeter 版本,因为较新的版本通常带有错误修复、性能改进和全新的功能,因此请考虑升级到 JMeter 3.2(或 JMeter Downloads 页面上提供的任何最新版本)

    【讨论】:

    • 感谢您的回复德米特里。我从 HTTP 标头管理器中删除了授权标头并使用了 HTTP 授权管理器。以下是我的授权经理的详细信息。 url="the-internet.herokuapp.com/basic_auth" username"admin" password"admin" mehcnism"BASIC_DIGEST" 详细信息正确。
    • 从 HTTP 标头管理器中删除您的授权标头对我有用!我不知道为什么
    猜你喜欢
    • 2020-07-05
    • 2021-06-17
    • 2018-05-18
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    相关资源
    最近更新 更多