Post a file in JMeter with Oauth signing

谁说胖子不能爱 提交于 2019-12-06 14:42:26

问题


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.

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?


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/25048339/post-a-file-in-jmeter-with-oauth-signing

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