4

I have a working curl command that I'd like to split out to make it easier to read.

curl d "valuea=1234&valueb=4567&valuec=87979&submit=Set" -XPOST "http://$ipa/school.cgi" > /dev/null

I've tried several ways to do this, but none seems to work.

curl -d "valuea=1234"\
     -d "valueb=4567"\
     -d "valuec=87979"\
     -d "submit=Set"\
 -XPOST "http://$ipa/school.cgi"

curl -d "valuea=1234\
         valueb=4567\
         valuec=87979\
         submit=Set"\
 -XPOST "http://$ipa/school.cgi"

Can someone advise how to do it ?

Thanks

2 Answers 2

4

The first approach is right, I experienced problems with spreading commands on multiple lines on some environments which were trimming whitespaces, hence it's a good idea to add a space before the backslashes:

curl -d "valuea=1234" \
     -d "valueb=4567" \
     -d "valuec=87979" \
     -d "submit=Set" \
  -XPOST "http://$ipa/school.cgi"

Eventually try it against a simple service which will inform you on what's receiving, like this one:

// echorequest.js
const http = require('http');

const hostname = '0.0.0.0';
const port = 3001;

const server = http.createServer((req, res) => {
  console.log(`\n${req.method} ${req.url}`);
  console.log(req.headers);

  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');

  let data = '';

  req.on('data', function(chunk) {
    data += chunk
  });

  req.on('end', function() {
    console.log('BODY: ' + data);
    res.end(data + "\n");
  });
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

... run by node echorequest.js (& change target of the command: -XPOST "localhost:3001")

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that a great help.
0

Also second approach could works by adding missing '&'.

For example

POST:

curl http://url -d \
"valuea=1234&\
valueb=4567&\
valuec=87979&\
submit=Set"

GET:

curl "http://url?valuea=1234&\
valueb=4567&\
valuec=87979&\
submit=Set"

If you need a service on the fly where to test your requests, try https://requestbin.fullcontact.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.