I want to send request payload as following in JMeter:
------WebKitFormBoundaryeBikRH0JCrgmtTvt
Content-Disposition: form-data; name="name"
test
------WebKitFormBoundaryeBikRH0JCrgmtTvt
Content-Disposition: form-data; name="description"
testing
------WebKitFormBoundaryeBikRH0JCrgmtTvt
Content-Disposition: form-data; name="configFile"; filename="test.json"
Content-Type: application/json
------WebKitFormBoundaryeBikRH0JCrgmtTvt--
So I tried to add the name and description part in Parameters tab with form-data as Content-type and added file in Files Upload tab in HTTP Request Sampler.
This is what I am getting in Request Body after execution:
POST data:
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1
Content-Disposition: form-data; name="name"
Content-Type: form-data; charset=US-ASCII
Content-Transfer-Encoding: 8bit
test
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1
Content-Disposition: form-data; name="description"
Content-Type: form-data; charset=US-ASCII
Content-Transfer-Encoding: 8bit
testing
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1
Content-Disposition: form-data; name="configFile"; filename="test.json"
Content-Type: application/json
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1--
I want to remove this part from the request for name and description part
Content-Type: form-data; charset=US-ASCII
Content-Transfer-Encoding: 8bit
This is resulting into failure with status code : 415
Need help on this please
If standard multipart HTTP Request generated by JMeter's HTTP Request sampler when you tick Use multipart/form-data box doesn't work for you be aware that you can manually build the HTTP Request by using:
HTTP Header Manager to set Content-Type header containing the boundary
__FileToString() function to load the contents of your .json file into the request body
Check Testing REST API File Uploads in JMeter for more comprehensive explanation and detailed example
Related
I am trying to upload file with string in JMeter. It doesn't work
POST http://localhost:8080/upload
POST data:
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r
Content-Disposition: form-data; name="input"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
{ "name": "John", "country": "US" }
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r
Content-Disposition: form-data; name="file"; filename="sample.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r--
[no cookies]
I got the following error using JMeter
{"code":"ERROR","message":"Required request parameter 'input' for method parameter type String is not present"}
I am able to hit the request using curl or Postman without any issues. Here is my curl request.
curl -i -X POST \
-H "Content-Type:multipart/form-data" \
-F "file=#\"./sample.txt\";type=text/plain;filename=\"sample.txt\"" \
-F "input={ \"name\": \"John\", \"country\": "US" }" \
'http://localhost:8080/upload'
If you're able to execute the request successfully using Postman you should be able to record the request using JMeter's HTTP(S) Test Script Recorder
Start the HTTP(S) Test Script Recorder
Configure Postman to use JMeter as the proxy
Copy the sample.txt file to "bin" folder of your JMeter installation
Run your request in Postman
JMeter will capture the request and generated proper HTTP Request sampler
More information: How to Convert Your Postman API Tests to JMeter for Scaling
We built a server which handles speech recorded by user using an app. The audio data is sent through http post in real time. The body looks like this:
--BOUNDARY
Content-Disposition: form-data; name="metadata"
Content-Type: application/json; charset="UTF-8"
<JSON FORMATTED METADATA HERE>
--BOUNDARY
Content-Disposition: form-data; name="audio"
Content-Type: application/octet-stream
<AUDIO BYTES HERE>
--BOUNDARY--
Now, I need to do load testing for the server. I am thinking of using ApacheBench and just do consistent uploading requests but I wish to use the same format as above for each request. How could that be setup in AB?
I was able to solve the problem by using the following command:
ab -p test -T "multipart/form-data; boundary=BOUNDARY" -c 1000 -n 1000 -l http://someipaddress.com/
where test is a file containing the post content.
The OpenAPI spec for the Create SMS Message endpoint includes the following request content types:
consumes:
- application/json
- multipart/mixed
- multipart/form-data
https://netstorage.ringcentral.com/dpw/api-reference/specs/rc-platform.yml?v=2019082420190816-0828
I found the SMS / MMS instructions to include a multipart/mixed example in the API Reference, but don't see any information on using multipart/form-data. I'm specifically interested in sending files.
https://developers.ringcentral.com/api-reference/SMS/createSMSMessage
The same API Reference shows support for both multipart/form-data and multipart/mixed for sending faxes.
https://developers.ringcentral.com/api-reference/Fax/createFaxMessage
Since both APIs send files and metadata so I'm wondering if the SMS API also supports multipart/form-data and, if so, how to send it?
No, it does not appear so.
The example you'd linked for the SMS message uses multipart/mixed to separate the API call itself (which is in turn sent as application/json) from the payload being sent as an MMS (image/png).
The use of multipart/form-data in the fax API is specific to the way that particular metadata is included, but there isn't an equivalent system for SMS/MMS as they both need that particular meta information encoded either as a single JSON document or as the JSON element of a multipart/mixed message.
To send a file, though, multipart/mixed is fine. Your request would then be something like:
POST /restapi/v1.0/account/403391985008/extension/403391985008/sms
Content-Type: multipart/mixed; boundary=Boundary_1_14413901_1361871080888
--Boundary_1_14413901_1361871080888
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{"to" :[{"phoneNumber": "+18772004569"},{"phoneNumber": "+18772094569"}],
"text" :"hello",
"from" :{"phoneNumber": "+18882004237"}}
--Boundary_1_14413901_1361871080888
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="filename.zip"
[Some encoded binary stream here ...]
--Boundary_1_14413901_1361871080888--
It'd be up to you to set the file's mime type properly and ensure things are encoded. The key points here are that the message information is encoded in the first JSON component in your multipart message, while the file attached to the MMS is encoded in the second.
multipart/form-data can be sent as shown in the following example:
POST / HTTP/1.1
HOST: platform.ringcentral.com/restapi/v1.0/account/~/extension/~/sms
Authorization: Bearer <MyToken>
Content-Type: multipart/form-data; boundary=12345
--12345
Content-Disposition: form-data; name="to"
+16505550101
--12345
Content-Disposition: form-data; name="to"
+16505550102
--12345
Content-Disposition: form-data; name="from"
+16505550100
--12345
Content-Disposition: form-data; name="text"
Hello World
--12345
Content-Disposition: form-data; name="attachment" filename="picture.jpg"
content of picture.jpg ...
--12345--
This can be done using curl as follows:
curl -XPOST https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~/sms \
-H 'Authorization: Bearer <MyToken>' \
-F 'to=+16505550101' \
-F 'to=+16505550102' \
-F 'from=+16505550100' \
-F 'text=Hello World' \
-F 'attachment=#picture.jpg'
How do you send an encrypted and html-formatted email through the command line? Here is the code I have so far:
# Encrypt email with a certificate
openssl cms -encrypt -in "/tmp/email_to_be_sent.html" -out "/tmp/encrypted.txt" -from $SENDER -to $RECEIVER -subject "Test: Encrypted message" -des3 "/tmp/$CERT.pem"
# Send the encrypted email
cat "/tmp/encrypted.txt" | sendmail -f $SENDER $RECEIVER
The generated encrypted email /tmp/encrypted.txt is as follow
To: recipient#mail.com
From: sender#mail.com
Subject: Test: Encrypted message
MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/pkcs7-mime; smime-type=enveloped-data;name="smime.p7m"
Content-Transfer-Encoding: base64
MIIDjAYJKoZIhvcNAQcDoIIDfTCCA3kCAQAxggFZMIIBVQIBADA9MDcxHDAaBgNVBAoME0V1cm9wZWFu
AxAlApQsmjzCwQoonT57JetCp7DHJdHWU1bkLIZWPPBRwa2EB0ZdxOXIvtg7rJavnnbxeTghblM45Pur
A+6BDKJbWvXFyxb...
The problem is, once in the recipient inbox and decrypted, the message is not html formatted and html code like <html><body></body></html> is still readable inside the message.
S/MIME requires the original message to be enveloped. This means that the original message is encrypted and this fact and the type of encryption is added to the outer message headers, so the client knows how to handle the message contents.
Because of this, the message headers that define the original message format need to be inside the S/MIME envelope, so the client knows which content type it is after decrypting the message.
The correct way is to extract these headers from the original message, then add them before the original message body. Note that these headers must start on the first line, and that after these headers a blank line is required before the original message body starts.
Headers that should be moved into the enveloped message data are
MIME-Version (optional)
Content-Type
Content-Transfer-Encoding
Content-Disposition (if exists)
"Moved" means that they should be included in the enveloped message data and removed from the outer message headers.
The remaining headers should be left in the envelope message. The openssl cms -encrypt command will then add the above headers as required for S/MIME encrypted messages.
Example
Original message
From: someone#somedomain.net
To: receipient#otherdomain.net
Subject: It's a test
MIME-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Custom-Header: Additional data
This is the message text.
Good night.
Moved headers before encryption (note the additional blank line)
From: someone#somedomain.net
To: receipient#otherdomain.net
Subject: It's a test
X-Custom-Header: Additional data
MIME-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
This is the message text.
Good night.
Message after encryption
From: someone#somedomain.net
To: receipient#otherdomain.net
Subject: It's a test
X-Custom-Header: Additional data
MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64
MIJ5lAYJKoZIhvcNAQcDoIJ5hTCCeYECAQAxggHZMIIB1QIBADCBvDCBtjEaMBgG
A1UEAwwRc2F2aWduYW5vIENFUlQtaTIxJTAjBgNVBAoMHHNhdmlnbmFubyBzb2Z0
d2FyZSBzb2x1dGlvbnMxHjAcBgNVBAsMFUNlcnRpZmljYXRpb24gU2VydmljZTEL
(more encrypted data removed)
So the comments from Stefan leaded me to the solution.
The unencrypted email /tmp/email_to_be_sent.html should have a header like this before encryption:
To: recipient#mail.com
From: sender#mail.com
Subject: Test: Encrypted message
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
<html><body><p> test message </p></body></html>
Beware that a newline is needed between the email header and the html code.
I am using Hadoop (CDH 5.4.8) to process the unstructured data and after successful processing I want to send a mail notification to the concerned team with log file as attachment.
CDH 5.4.8 Oozie does not support attachment feature in email action. So I want to do this using shell script. Please let me know the best way to do this.
You can easily send an email from within a shell by piping a complete mail message (header and body) into sendmail. This assumes that the host you're doing this is properly configured with a mail transfer agent (e.g. sendmail or postfix) to send email messages.
The easiest way to send email with an attachment is to create a simple template message in your mail user agent (e.g. Thunderbird), and copy its contents as a template with the view source command. Modify that template to suit your needs and place it in the shell script.
Here is an example:
#!/bin/sh
cat <<\EOF |
To: Ramesh <ramesh#example.com>
From: Diomidis Spinellis <dds#aueb.gr>
Subject: Here are your Hadoop results
Message-ID: <5700BF28.2070500#aueb.gr>
Date: Sun, 3 Apr 2016 09:58:48 +0300
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------030303090406090809090501"
This is a multi-part message in MIME format.
--------------030303090406090809090501
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
The attachment contains your Hadoop results.
--------------030303090406090809090501
Content-Type: application/octet-stream;
name="data"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="data"
HviDNR105+2Tr0+0fsx3OyzNueQqPuAXl9IUrafOi7Y=
--------------030303090406090809090501--
EOF
sendmail ramesh#example.com
To configure a fixed message with actual data, replace the parts you want to modify with commands that generate them. (Note the missing backslash from the here document EOF marker.)
#!/bin/sh
cat <<EOF |
To: Ramesh <ramesh#example.com>
From: Diomidis Spinellis <dds#aueb.gr>
Subject: Here are your Hadoop results
Message-ID: <5700BF28.2070500#aueb.gr>
Date: $(date -R)
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------030303090406090809090501"
This is a multi-part message in MIME format.
--------------030303090406090809090501
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
The attachment contains your Hadoop results.
--------------030303090406090809090501
Content-Type: application/octet-stream;
name="data"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="data"
$(base64 binary-data-file.dat)
--------------030303090406090809090501--
EOF
sendmail ramesh#example.com