question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to pass json?

See original GitHub issue

Hello Im really broke my head trying to pass json to cannon. I want to send application/json Let me show all cases that im try:

  • autocannon -m PUT -b "{\"playerId\":\"8797982347\" }" https://localhost:3434/player
  • autocannon -m PUT -b '{"playerId":"8797982347" }' https://localhost:3434/player
  • ofcourse autocannon -m PUT -b {"playerId":"8797982347" } https://localhost:3434/player
  • and many other cases like --body= or with --input.

And also I try more from this with -H "Content-Type: application/json"

Can somebody help me and tell what type of escaping I must use for sending json

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
LandimTiagocommented, Dec 26, 2022

Hi, I found the solution, it is necessary to specify the header so that it accepts the body.

Exemple: URL=http://localhost:3000/api/v1/login

npx autocannon $URL -m POST --header ‘Content-Type: application/json’ --body ‘{“username”: “USER_NAME”,“pass”: “PASS_123”}’ --connections 100 --duration 10 --pipelining 1 --renderStatusCodes

0reactions
james-innescommented, Dec 26, 2022

Must admit I can’t get this to work with express either using same variety of options.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Send and Receive JSON Data to and from the Server
Create a JavaScript object using the standard or literal syntax. · Use JSON.stringify() to convert the JavaScript object into a JSON string. ·...
Read more >
How to pass JSON data using HTTP Request action
To add the JSON data in the body of the 'HTTP Request', select 'raw' from the list of options and enter your JSON...
Read more >
How to pass a JSON array as a parameter in URL
Take the JSON object and convert it to string (JSON.stringify) · Take the string and encode it in Base64 (you can find some...
Read more >
How to send a JSON object to a server using Javascript?
So we are using JSON.stringify() function to convert data to string and send it via XHR request to the server. Below is the...
Read more >
How to post JSON data using Curl? - ReqBin
JSON data is passed as a string. Double quotes in JSON must be escaped with the backslash "\" on Windows computers. In this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found