groovy JMeter中GET API调用需要Hawk身份验证

x9ybnkn6  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(129)

我有一个GET API请求,需要通过JMeter,但它需要Hawk身份验证。我也有Hawk身份验证ID,Hawk身份验证密钥,算法值。
在postman中,它工作正常,但当将postman脚本转换为JMeter脚本并执行时,它会给出一个错误消息,如“未授权”和响应代码- 401。
因此,我需要了解JMeter中Hawk身份验证的配置过程。
有人能帮我吗?

6rqinv9w

6rqinv9w1#

请尝试Hawk Java API implementation,示例代码可在
Building Your Own -> Clients文档一章中提供了示例代码和说明,以防我在这里复制代码片段:

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预处理器中
之后,添加一个HTTP Header Manager,并将其配置为发送值为${authorizationHeader}Authorization报头

相关问题