【问题标题】:Required Hawk Authentication for a GET API Call in JMeterJMeter 中 GET API 调用所需的 Hawk 身份验证
【发布时间】:2022-07-05 23:47:23
【问题描述】:

我有一个 GET API 请求,需要通过 JMeter 传递它,但它需要 Hawk 身份验证。我还有 Hawk Auth ID、Hawk Auth Key 、算法值。

在邮递员中它工作正常,但是当将该邮递员脚本转换为 JMeter 脚本并执行时,它会给出一条错误消息,例如“未经授权”和响应代码 - 401。

所以我需要知道JMeter中Hawk认证的配置过程。

谁能帮我解决这个问题??

【问题讨论】:

    标签: groovy jmeter jmeter-plugins jmeter-5.0


    【解决方案1】:

    试用Hawk Java API implementation,示例代码在

    Building Your Own -> Clients 文档章节中提供了带有解释的示例代码,以防万一我在这里复制代码 sn-p:

    import com.wealdtech.hawk.HawkClient
    import com.wealdtech.hawk.HawkCredentials
    import com.wealdtech.hawk.HawkCredentials.Algorithm
    
    //If you want your clients to authenticate using Hawk then you will need to start with a set of Hawk credentials:
    
    HawkCredentials hawkCredentials = new HawkCredentials.Builder()
                                                         .keyId("dh37fgj492je")
                                                         .key("werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn")
                                                         .algorithm(Algorithm.SHA256)
                                                         .build();
    
    //Once these have been configuration you can create a Hawk client:
    
    HawkClient hawkClient = new HawkClient.Builder().credentials(hawkCredentials).build();
    
    //And then for each request that you wish to send you need to generate an authorization header:
    
    String authorizationHeader = hawkClient.generateAuthorizationHeader(uri, method, body, ext);
    
    //This string needs to be added to the outgoing HTTP request as the content of the "Authorization" header. 
    
    //and JMeter specifics:
    
    vars.put('authorizationHeader', authorizationHeader)
    

    此代码需要放入JSR223 PreProcessor

    然后添加一个HTTP Header Manager 并将其配置为发送Authorization 标头,其值为${authorizationHeader}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      • 2014-01-31
      • 2017-03-17
      • 1970-01-01
      • 2015-03-26
      • 2017-06-13
      相关资源
      最近更新 更多