abao
abao copied to clipboard
multipart/form-data request not sending content-type header
I'm trying to test a multipart/form-data endpoint but it seems as though the content-type header isn't being sent when I run abao.
Raml snippet:
/stuff:
put:
body:
multipart/form-data:
formParameters:
name:
description: The name of the stuff
required: true
type: string
example: My_Stuff
image:
description: A picture of the stuff
required: true
type: file
responses:
201:
body:
application/json:
If I change multipart/form-data
to application/json
I can see the request getting further (but then fails because the required input isn't passed... as expected)
Thoughts?
Thanks Kimo
Abao send application/json
in default as it only support json validation now. But you can let Abao sent other MIME type like multipart/form-data
by writing a hookfile. You can find instructions of writing hookfile in README.
Hi @cybertk: can you tell me how to add a file in a hook? I did something like this but it doesn't work:
test.request.headers['Content-Type'] = 'multipart/form-data; boundary=---------------------------1855940011132119363825021521';
test.request.body = '---------------------------1855940011132119363825021521\n' +
'Content-Disposition: form-data; name="image"; filename="source2.png"\n' +
'Content-Type: image/png\n\n' +
fs.readFileSync('/tmp/image/source2.png') + '\n' +
'---------------------------1855940011132119363825021521--\n';
any idea?
I am sorry, abao does not support this now. It only support json
payload
@cybertk: thanks for the info. It might be a nice feature for abao :)
:+1:
yes , it should be important for us.
Is there a way to send multipart/form-data content in request.
If so how do I send it please refer to the below node js script for your reference:
var request = require("request");
var options = { method: 'POST', url: 'http://url/add_requester', headers: { authorization: 'token', 'content-type': 'multipart/form-data; boundary=---011000010111000001101001' }, formData: { name: 'test name', username: 'testuserjjf', email: '[email protected]', handphone_number: '+62345-23456789', nik: '' } };
Can formdata json above be included in hookfile, if so how ? my api accepts data in mutipart/form-data format as per wire shark trace.