使用 Oauth 签名在 JMeter 中发布文件 [英] Post a file in JMeter with Oauth signing

查看:25
本文介绍了使用 Oauth 签名在 JMeter 中发布文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Following is what I want to implement using JMeter: I want to make a request to an API that implements OAuth signing. The API makes a POST request with a binary file.

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

I am trying to use OAuth Request sampler plugin. This plugin, unlike HTTP Request sampler, doesn't have 'Send Files with the Request' option.

还有什么方法可以实现吗?

Is there some way I can still implement it?

推荐答案

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

To people who might not be familiar with jmeter. Here is sample code. Add a beanshell sampler and write in Java to sign the request and inject the authorization header into the http request sampler afterwards.

这里是beanshell采样器的代码

Here is the code for beanshell sampler

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;

这篇关于使用 Oauth 签名在 JMeter 中发布文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆