2

I use postman to send POST requests. I use form fields and I have a field "data". In these field I paste the complete content of a xml-file. It work fine!

Now I want use CURL to send this POST request with dynamic XML-content. But I looking for a simple way to fill the XML content in the field "data" on CURL command.

I try:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data "data=@/my/file/path" http://localhost:3001/import/myservice

If I check the request in my nodejs code there is no content in request params only the filename.

My node code is:

router.post('/import/myservice', function(req, res) {
   let data = req.body.data;
   ... }

Content of data is "@/my/file/path" but I need something like

data= '<?xml version="1.0" encoding="ISO-8859-1"?> ...'
Gerd
  • 2,265
  • 1
  • 27
  • 46

1 Answers1

-1

If you put your data in a file you should enter the line like below:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data "@my.file.path" http://localhost:3001/import/myservice

Take a look right here it might help.

Community
  • 1
  • 1
Keylies
  • 32
  • 4
  • --data "data=@my.file.path" ==> data = '@my.file.path' (nodejs) and --data "@my.file.path" not working for me, I need formdata. – Gerd Apr 06 '17 at 13:31
  • 1
    @brett I rember, my solution was: discard the file read-way. Use http://meyerweb.com/eric/tools/dencoder/ and do the encoded XML direct in the -data option. Hope it help's. – Gerd Jun 01 '18 at 13:13