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

查看:134
本文介绍了使用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 Request采样器插件.与HTTP Request采样器不同,此插件没有使用Request发送文件"选项.

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天全站免登陆