Post a file in JMeter with Oauth signing

非 Y 不嫁゛ 提交于 2019-12-04 19:24:58

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.

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;

Did you try authenticating first using OAuth sampler then sending the file using regular http sampler.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!