LoadRunner Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Need code for the web_custom_request.

SOLVED
Go to Solution
Occasional Advisor

Need code for the web_custom_request.

Hi All,

I request your help for the below.

 

My script has XML message in web_custom_request. I am saving this XML content alone in lr_save_string and substituting this string value in web_custom_request.

 

My XML message contains message ID followed by body of the message ,this makes one request with one message. My question here is how can I make this for multiple messages by changing the message ID and the content of the body with different parameters.

 

For example.

 

web_custom_request (“My soap”,

“URL=https://myurl.com/

“Body=message ID=1000,\r\nContent–Disp"

"position: form–data=1234; name=\"entry\"\r\n\r\nText\r\n”,

LAST)

 

The above request sends one request. If I want multiple messages, for example if I specify my message count = 5 in my script then the custom request should look like below with different msg ID.

 

web_custom_request (“My soap”,

“URL=https://myurl.com/

“Body=message ID=1000,\r\nContent–Disp"

"position: form–data=1234; name=\"entry\"\r\n\r\nText\r\n”,

message ID=1001,\r\nContent–Disp"

"position: form–data=2345; name=\"entry\"\r\n\r\nText\r\n”

message ID=1002,\r\nContent–Disp"

"position: form–data=6789; name=\"entry\"\r\n\r\nText\r\n”

message ID=1003,\r\nContent–Disp"

"position: form–data=9807; name=\"entry\"\r\n\r\nText\r\n”

message ID=1004,\r\nContent–Disp"

"position: form–data=3456; name=\"entry\"\r\n\r\nText\r\n”

LAST)

 

I just need to know how can I write the code for this. This would be highly appreciable.

 

Kind Regards

Shankar

3 REPLIES
Trusted Contributor

Re: Need code for the web_custom_request.

[ Edited ]

Hi,

 

I am not sure if this is gone work, try it first:

1. Put a part of the request in a parameter called 'MultipleMessages'

2. Put the parameter '{MultipleMessages}in the WEB_CUSTOM_REQUEST.

 

Step 1. lr_save_string("position: form–data=1234; name=\"entry\"\r\n\r\nText\r\n","MultipleMessages");

 

Step 2.

web_custom_request (“My soap”,
“URL=https://myurl.com/
“Body=message ID=1000,\r\nContent–Disp"
"{MultipleMessages}",
LAST);

 

If this works then you should think about using STRCPY, STRCAT and a FOR loop to do the trick.

 

 

 

 

NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.
Occasional Advisor

Re: Need code for the web_custom_request.

Hi Dennis,

 

This is working for me .But how do i proceed to loop it for multiple meaagses with different meg ID and other parameters.

 

Thanks

Shankar

Highlighted
Trusted Contributor

Re: Need code for the web_custom_request.

Hi Shankar,

 

That should be something like this:

 

char prmMessage[1024]; // buffer 1024 bytes, adjust if needed
char prmNextLine[64]; // buffer 64 bytes
char prmMessageID[16]; // buffer 16 bytes
char prmFormdata[16]; // buffer 16 bytes
int i; // integer value

// Create empty string
strcpy(prmMessage, "");

// loop 5 times
for(i=0; i<5; i++){
	
	// insert your Formdata logic here
	sprintf(prmFormdata, "%04d", i*1000);
	
	// insert your MessagID logic here
	sprintf(prmMessageID, "1%03d", i);
	
	// Create line to add to MultipleMessage request
	// Data will be replaced with %s in sprintf-statement
	sprintf(prmNextLine, "position: form–data=%s; name=\"entry\"\r\n\r\nText\r\nmessage ID=%s,\r\nContent–Disp", prmFormdata, prmMessageID);
	// Add new line to MultipleMessage
	strcat(prmMessage, prmNextLine);
}

// Copy created message to variable MultipleMessages
lr_save_string(prmMessage, "MultipleMessages");

 

Output will be something like:

Notify: Saving Parameter "MultipleMessages = position: form–data=0000; name="entry"\r\n\r\nText\r\nmessage ID=1000,\r\nContent–Dispposition: form–data=1000; name="entry"\r\n\r\nText\r\nmessage ID=1001,\r\nContent–Dispposition: form–data=2000; name="entry"\r\n\r\nText\r\nmessage ID=1002,\r\nContent–Dispposition: form–data=3000; name="entry"\r\n\r\nText\r\nmessage ID=1003,\r\nContent–Dispposition: form–data=4000; name="entry"\r\n\r\nText\r\nmessage ID=1004,\r\nContent–Disp".

 

Further coding you have to do by yourself.

Hopefully I pushed you in the right direction.

 

 

NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.