jMeter: upload sequentially named files - jmeter

I've several files containg POST body requests.I'd like to send those requests in parallel using jmeter.
Currently, I'm using curl + parallel command apporach.
Related curl command is like:
curl -s -X POST $FHIR_SERVER/ -H "Content-Type: application/fhir+json" --data "#patient-bundle-01.json"
Request bodies are files like patient-bundle-xx, where xx is a number. Currently, I'd like to send up to 1500 requests using this incremental pattern.
My approach using parallel:
doit() {
bundle="$1"
curl -s -X POST $FHIR_SERVER/ -H "Content-Type: application/fhir+json" --data "#patient-bundle-$bundle.json"
}
export -f doit
export FHIR_SERVER
seq -w 99 | parallel -j77 doit
How could I get this behavior using jmeter?

Add a Counter configuration element and specify desired start and end value
In your HTTP Request sampler add ${bundle} JMeter Variable reference to the file name
More information: How to Use a Counter in a JMeter Test
Another (easier) option could be using Directory Listing Config plugin

Related

How to for loop CURL commands?

I am using Watson's Speech-To-Text Lite service and I am trying to find a way to automate the loading of new audio files to transcribe. I am very new to Bash and so I'm unclear of even the more rudimentary terms - so I'm finding the problem hard to find a solution for.
For a single use-case, I run the following file (my API key omitted with 'MY APIKEY')
curl -X POST -u "apikey: MY APIKEY" --header "Content-Type: audio/flac" --data-binary "#audiofile_1.flac" "https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel&speaker_labels=true" > C:/Users/outputpath/output_1.txt
What I am essentially trying to achieve is to overcome having to manually type and retype the names of the audio files and output. So if I had three (or more) audio files (i.e. audiofile_1, 2, and 3.flac), i would like to create an output file corresponding to each audio file - Some psuedo-code that might help explain what I mean would be
files = [file_1, file_2, file_3]
for file_x in files:
run curl command
save as output_x
You almost got it. You just need to learn some shell syntax:
files=("file_1" "file_2" "file_3")
for file_x in "${files[#]}"
do
curl -X POST -u "apikey: MY APIKEY" --header "Content-Type: audio/flac" --data-binary "#${file_x}" "https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel&speaker_labels=true" > "C:/Users/outputpath/${file_x}.txt"
done
First you create the files array with your list of files. Then, you iterate over those files and run the curl command on each of them.

Curl command not uploading file contents

Hi I am using cURL command to upload a file which is a POST request to my local machine service.
I am using following commands to upload
curl -i -X POST -H "Content-Type: multipart/form-data" -F
"/Users/myName/Folder/file.csv" http://localhost:port/api/fileupload
In my application side I am using spring frameworks web binding to receive the file
Following is the code snippet
public ResponseEntity importDimensions(#RequestBody MultipartFile file) {
// file is variable is always null
}
What am I missing here?
You need an # sign before the filename, like this: #/Users/myName/Folder/file.csv.
And if your server-side code is expecting a parameter named file then you need to do this:
-F "file=#/Users/myName/Folder/file.csv"

what does `curl -e` or `curl --referer` mean?

I've seen some example :-
curl --referer http://example.com/bot.html http://www.cyberciti.biz/
what is the different if I use curl http://www.cyberciti.biz/
shell script type:-
curl -e http://example.com/bot.html \
'http://www.cyberciti.biz/'
what is \ for?
From the man page of cURL
-e, --referer <URL>
(HTTP) Sends the "Referrer Page" information to the HTTP server. This
can also be set with the -H, --header flag of course. When used with
-L, --location you can append ";auto" to the --referer URL to make curl automatically set the previous URL when it follows a Location:
header. The ";auto" string can be used alone, even if you don't set an
initial --referer.
Essentially this tells the server which page sent you there.

Bash curl POST a binary variable

How do you POST a binary variable in curl bash?
#!/usr/bin/env bash
IMAGE=$(curl "http://www.google.com/images/srpr/logo3w.png")
curl --data-binary "$IMAGE" --request "POST" "http://www.somesite.com"
Curl seems to do corrupt the image when uploading.
Curl has the option to write response to disk and then read from it, but it'd be more efficient to do it solely in memory.
Try to eliminate the variable ... as follows:
curl "http://www.google.com/images/srpr/logo3w.png" | curl --data-binary - --request "POST" "http://www.somesite.com"
From the curl man page:
If you start the data with the letter #, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin.
EDIT: From the man page, too:
--raw When used, it disables all internal HTTP decoding of content or transfer encodings and instead makes them passed on unaltered, raw. (Added in 7.16.2)
What happens, if applied on either or both sides?
I had a related problem, where I wanted to dynamically curl a file from a given folder.
curl --data-binary directory/$file --request "POST" "http://www.somesite.com"
did not work - uploaded the string "directory/myFile.jar" instead of the actual file.
Adding the # symbol
curl --data-binary #directory/$file --request "POST" "http://www.somesite.com" fixed it.

Using CURL to download file and view headers and status code

I'm writing a Bash script to download image files from Snapito's web page snapshot API. The API can return a variety of responses indicated by different HTTP response codes and/or some custom headers. My script is intended to be run as an automated Cron job that pulls URLs from a MySQL database and saves the screenshots to local disk.
I am using curl. I'd like to do these 3 things using a single CURL command:
Extract the HTTP response code
Extract the headers
Save the file locally (if the request was successful)
I could do this using multiple curl requests, but I want to minimize the number of times I hit Snapito's servers. Any curl experts out there?
Or if someone has a Bash script that can respond to the full documented set of Snapito API responses, that'd be awesome. Here's their API documentation.
Thanks!
Use the dump headers option:
curl -D /tmp/headers.txt http://server.com
Use curl -i (include HTTP header) - which will yield the headers, followed by a blank line, followed by the content.
You can then split out the headers / content (or use -D to save directly to file, as suggested above).
There are three options -i, -I, and -D
> curl --help | egrep '^ +\-[iID]'
-D, --dump-header FILE Write the headers to FILE
-I, --head Show document info only
-i, --include Include protocol headers in the output (H/F)

Resources