Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing of jmeter variables in post data #2045

Closed
asfimport opened this issue Nov 13, 2007 · 5 comments
Closed

allow passing of jmeter variables in post data #2045

asfimport opened this issue Nov 13, 2007 · 5 comments

Comments

@asfimport
Copy link
Collaborator

Chris Cooper (Bug 43850):
I recently modified source code to enable me to insert variables into post data
quite easily actually. In HTTPSampler when sending post data and iterating
through the GUI arguments just changed the code to look something like this:

while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();

            int left = arg.getValue().indexOf("{");
            int right = arg.getValue().indexOf("}", left);
            
            String val = arg.getValue();
            if ((left != -1) && (right != -1)) {
            	// we may have a variable
            	String varName = arg.getValue().substring(left + 1, right);
            	val =

JMeterContextService.getContext().getVariables().get(varName);
// this variable isn't defined or this wasn't actually a variable
if (val == null)
val = arg.getValue();
}

            parts[partNo++] = new StringPart(arg.getName(), val,

contentEncoding);
}
This allows for a variable defined by JMeter to be inserted, particularly useful
for multiple threads needing different values in a URL and if the variable
doesn't exist it just keeps the value in.

OS: All

Duplicated by:

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
Variable substitution already works for POST arguments in JMeter 2.3.

If it is not working for you, please attach a test case to this issue.

@asfimport
Copy link
Collaborator Author

Ravi Challapalli (migrated from Bugzilla):
I am using JMeter 2.5.1 and using the 'Random Variable' - the variable substitution does not work for POST data.
I did:

  1. Create a random variable 'myVar'
  2. Created a http request - method POST
  3. Added a file in the 'Send Files With the Request' (Note: 'Use multipart/form-data...' is un checked)
  4. Used the above created random variable place holder ${myVar} in the file added above step

Tried with JMeter 2.3.4 version which also did not work.

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
(In reply to comment 2)

I am using JMeter 2.5.1 and using the 'Random Variable' - the variable
substitution does not work for POST data.
I did:

  1. Create a random variable 'myVar'
  2. Created a http request - method POST
  3. Added a file in the 'Send Files With the Request' (Note: 'Use
    multipart/form-data...' is un checked)
  4. Used the above created random variable place holder ${myVar} in the file
    added above step

JMeter has never supported variable substitution in external files, only in fields on the Gui screen.

Tried with JMeter 2.3.4 version which also did not work.

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
See #996 to check that you're in the same scenario.
I think it's a duplicate.

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
This bug has been marked as a duplicate of #996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant