Uploading file to rest API using JMeter - post

Note - I have checked BlazeMeter Tutorial which uploads doc as Body Data while I use File Upload tab.
Here is how my request looks -
On execution I get following Request -
POST https://xxx
POST data:
<actual file content, not shown here>
[no cookies]
Request Headers:
Connection: keep-alive
Content-Type: multipart/form-data
Accept-Language: en-US
Authorization: bearer <>
Accept: application/json
Content-Length: 78920
Host: test-host
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_102)
And the request fails with 400 error -
Response code: 400
Response message: Bad Request
Since I am able to carry out file upload using curl, I assume that I missed the some configuration with JMeter. Curl looks as -
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer <>' -F upload_file=#"test.pdf" 'https://xxx'
What did I miss in JMeter file upload?

Another vote for using the Java implementation in the Advanced tab in Jmeter. My headers and body were exactly the same between postman and jmeter, but it wouldn't upload my file (got response code 415) until I changed to the Java implementation.

If you can successfully upload file via curl, why don't you just record the upload through JMeter HTTP(S) Test Script Recorder like:
curl -x http://localhost:8888 -X POST --header 'Content-Type....."
If you still need to build the request manually consider two important bits:
You need to check Use multipart/form-data for POST.
The most significant, you need to supply "Parameter Name", According to HTTP Request Sampler Manual:
For the POST and PUT method, if there is no file to send, and the name(s) of the parameter(s) are omitted, then the body is created by concatenating all the value(s) of the parameters.
Looking into curl command manual in your case the "Parameter Name" should be upload_file
So the final configuration should look like:
See Performance Testing: Upload and Download Scenarios with Apache JMeter guide for above steps described in details.

My backend server is implemented in Java and in the file upload request I had to select the Impolementation as Java!
Here is the file upload section

thank you for the JAVA implementation of HTTP! file uploads are working again for me which haven't worked since 2.13
here's my post else where:
I had same issue...thought jmeter was doing something wrong since this stuff worked for me in 2.13...hasn't worked since version 3. well..saw a post somewhere that said, using the JAVA implementation of HTTP worked. Guess what? it did work for me too!!! I've been struggling trying to dissect every part of the POST. I was doing it right all along, just needed JAVA implementation of HTTP and voila!
hope that helps!

Related

trying to send https string to website in lua

I am sort of new to lua and I have API that I need to call.
"https://status.abc.com/integrations/plus/?endpoint="..number.."&server="..server
This is not in a json format. It is just sending this http string to a web server. What is the simplest way to acomplish this?
local ok =os.execute([[curl --cert /etc/openvpn/cert.crt --key /etc/openvpn/key.key -X POST -H 'Content-Type: application/x-www-form-urlencoded' 'url here' --data 'data here']])
Try looking into the LuaSec library.
There is no https support native to lua so your (as far as i know) only option is to build LuaSec or try to find a build on the internet

Adding private key to Google audio to text API

I have submitted a request for google Audio to text. I received the name back, but I am unsure how to add private key info from file downloaded to:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://speech.googleapis.com/v1/operations/your-operation-name"
and then am I able to run the command from web or Mac?
You can set up the environment variable to use the private key as mentioned here. Though the link talks about Vision API, the process is similar to use Cloud Speech-to-Text API. Also, here is additional documentation for authentication. This can be run from the web.

How to specify headers in zabbix web monitoring

I need to monitor this curl command using zabbix.
curl -i -H "APPLICATIONKEY: kfkdiekd859662" -H "CONSUMERKEY: jdjdjd655222" -X POST https://test.api-test.com/confirm.
I have given the URL in url column.
I have been facing issue on how to specify the header in zabbix-web monitoring.
Under step tab.
Guide me, on how to specify header in zabbix.
You can specify headers in the "Headers" field like so:
APPLICATIONKEY: kfkdiekd859662
See the web scenario entry in the Zabbix manual for more detail.

restify example TODO server not sending responses

I'm new at this and developing my first API server. I wanted to see an example of a POST request so I installed restify 3.0.3 and tried to run the TODO server example. I see the requests logged at the server but no response is sent. I'm using the sample curl requests provided and the server is running on Cloud9. Curl is running on windows 7.
For example, I've tried:
curl -isS http://test-atk9.c9.io | json
curl -isS http://test-atk9.c9.io/todo -X POST -d name=demo -d
task="buy milk"
Can anyone help?
I saw the same behavior when using PostMan to exercise the example.
Setting the PostMan Header Accept:text/plain or Accept:application/json worked for me.
BTW: if you set Accept:text/html, you should receive a helpful response:
{
"code": "NotAcceptableError",
"message": "Server accepts: application/todo,application/json,text/plain,application/octet-stream,application/javascript"
}
Hope this helps.

Extract text content from Tika without specifying the file header

Is there a way to extract content from a file with a Tika server without explicitly defining the header? For example for a specific file named "file.pdf" if I do
curl -X PUT --data-binary #file.pdf localhost:9998/tika --header "Content-type: application/pdf" > file.txt
I get the extracted content in "file.txt" but if I omit the
' --header "Content-type: application/pdf" '
I get an empty "file.txt".
In general is there a way to automate the process of submitting a document to a tika server and extracting the content in txt with a single command?
Or alternatively how can I use a pipeline to redirect a possible Tika header output answer of a file to the command in the beginning of this question?
Thank you very much community!
You're calling the Tika Server wrong to get auto-detection. As detailed on the Tika Server wiki page, to have the plain text extracted from any file (including PDF) you should run Curl as:
curl -T file.pdf http://localhost:9998/tika --header "Accept: text/plain"
You need an accept header to tell Tika what format you want your result in (Plain Text or HTML for text extraction, more formats available for metadata). As long as you send the file directly with the -T option, its type will be auto-detected for you

Resources