Delivering a payload to a URL, using cURL

0

I need help figuring out the cURL request required to send the following data to a URL.

{"requestid":"555555", 
"partnermatchid":"10000-000-0000-0000-000", 
"usercontext":{"ipaddressmasked":"XXX.XXX.X.XXX", 
"useragent":"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.10 (khtml, like gecko) chrome/28.0.1500.95 safari/537.36", 
"country":"us"}, 
"pagecontext":{"pagetypeid":"2","numslots":"3"}, 
"istest":false}

My main issue is that I can't figure out how to format the payload above to be sent properly to a URL. So far, I have been utilizing the -d and -X POST commands. I am using Git Bash.

I appreciate your help and input.

Mark

Posted 2015-09-25T07:32:53.003

Reputation: 1

Can you explain why it isn't working? Is the format wrong, or is the command itself failing, or is the server rejecting your input for some weird reason, or...? – CBHacking – 2015-09-25T09:07:17.803

Answers

0

It should be something like this:

echo '{"requestid":"555555", 
"partnermatchid":"10000-000-0000-0000-000", 
"usercontext":{"ipaddressmasked":"XXX.XXX.X.XXX", 
"useragent":"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.10 (khtml, like gecko) chrome/28.0.1500.95 safari/537.36", 
"country":"us"}, 
"pagecontext":{"pagetypeid":"2","numslots":"3"}, 
"istest":false}' | curl --data-binary @- -H "Content-Type: text/json" <URL>

The interesting parts:

  • The echo at the beginning is just to get the body content into pipe to curl. Note the use of single-quotes to prevent bash from interpreting any of the quotation marks or anything in the JSON.
  • The use of --data-binary is to tell curl to send the body exactly as-is, unmodified. The @- part tells it to read from stdin (in this case, the pipe from echo.
  • The `-H "Content-Type: text/json" might not be needed, but servers often get grumpy if there's a request body and the content-type isn't specified.
  • I did not include a User-Agent header. You have a UA string in the JSON, so hopefully the server isn't going to be picky about the UA header, but you can easily override curl's default UA string if you want to.
  • <URL> is, of course, the URP that you want to send your POST to. Note that if it's an HTTPS URL and the certificate isn't trusted by curl, you'll need to tell curl to use insecure mode (-k flag).

CBHacking

Posted 2015-09-25T07:32:53.003

Reputation: 5 045