【问题标题】:Post a file in JMeter with Oauth signing使用 Oauth 签名在 JMeter 中发布文件
【发布时间】:2014-09-22 18:35:37
【问题描述】:

以下是我想使用 JMeter 实现的:我想向实现 OAuth 签名的 API 发出请求。 API 使用二进制文件发出 POST 请求。

我正在尝试使用 OAuth 请求采样器插件。与 HTTP 请求采样器不同,此插件没有“使用请求发送文件”选项。

有什么方法我仍然可以实现它吗?

【问题讨论】:

  • 我认为您可以编写内容创建脚本,但这当然不是很舒服。

标签: oauth jmeter jmeter-plugins


【解决方案1】:

致那些可能不熟悉 jmeter 的人。这是示例代码。 添加一个beanshell采样器并用Java编写对请求进行签名并将授权标头注入到http请求采样器中。

这是 beanshell 采样器的代码

import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import org.apache.http.client.methods.HttpPost;




log.info("start of signing the request");

String consumerKey = "[consumerKey]";
String consumerSecret ="[consumerSecret]";
String token = "[token]";
String secret = "[secret]"; 

OAuthConsumer consumer;
consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
consumer.setTokenWithSecret(token, secret);

HttpPost request = new HttpPost("[url]");
consumer.sign(request);

System.out.println(request.getFirstHeader("Authorization").toString());
String oauth = request.getFirstHeader("Authorization").toString().substring(15);
vars.put("oauth" ,oauth);

return oauth;

【讨论】:

    【解决方案2】:

    您是否尝试过先使用 OAuth 采样器进行身份验证,然后使用常规 http 采样器发送文件。

    【讨论】:

    • OAuth 插件似乎有问题。它不适用于最新版本的 JMeter。但是,我通过编写一个将 OAuth 签名添加到标头的 BeanShell 预处理器来使其工作。然后,我使用了默认的 Http Request 采样器。
    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多