Bug 43850 - allow passing of jmeter variables in post data
Summary: allow passing of jmeter variables in post data
Status: RESOLVED DUPLICATE of bug 15468
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 2.5.1
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-13 07:55 UTC by Chris Cooper
Modified: 2012-01-24 18:12 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Cooper 2007-11-13 07:55:22 UTC
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.
Comment 1 Sebb 2007-11-13 08:16:34 UTC
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.
Comment 2 Ravi Challapalli 2012-01-24 16:29:50 UTC
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.
Comment 3 Sebb 2012-01-24 17:01:26 UTC
(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.
Comment 4 Philippe Mouawad 2012-01-24 18:12:03 UTC
See BUG 15468 to check that you're in the same scenario.
I think it's a duplicate.
Comment 5 Philippe Mouawad 2012-01-24 18:12:19 UTC

*** This bug has been marked as a duplicate of bug 15468 ***
Comment 6 The ASF infrastructure team 2022-09-24 20:37:40 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2045