Highlighted
Absent Member.
Absent Member.
10302 views

Need code for the web_custom_request.

Jump to solution

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

1 Solution

Accepted Solutions
Highlighted
Honored Contributor.
Honored Contributor.

Re: Need code for the web_custom_request.

Jump to solution

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.

View solution in original post

4 Replies
Highlighted
Honored Contributor.
Honored Contributor.

Re: Need code for the web_custom_request.

Jump to solution

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.
Highlighted
Absent Member.
Absent Member.

Re: Need code for the web_custom_request.

Jump to solution

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
Honored Contributor.
Honored Contributor.

Re: Need code for the web_custom_request.

Jump to solution

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.

View solution in original post

Highlighted
Contributor.
Contributor.

Re: Need code for the web_custom_request.

Jump to solution

Hi, 

Even I have the same requirement. Can you please tell me how did you resolve this.

My requirement is : I have a soap request in which few tags in the request should be repeated multiple times (Eg : 1000 times). If I split the soap request into different actions and try to use blocks, it is throwing errors. How to use for loop and repeat few tags in the soap request. Please help me with this. 

TIA

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.