Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Question) How can I pass a JSON body? #314

Closed
ViniciusLucchesi opened this issue Sep 22, 2023 · 2 comments
Closed

(Question) How can I pass a JSON body? #314

ViniciusLucchesi opened this issue Sep 22, 2023 · 2 comments

Comments

@ViniciusLucchesi
Copy link

I developed an Actix-web API, and the route that I want to test requires a JSON body like this:

{
  "code": "7843.92.73"
}

I tried the following URL based on @hatoo's response to kenessajr's issue, but it didn't work.

oha -T application/json -d 'code=7843.92.73' 'http://127.0.0.1:7000/code/view'

The response from oha was Status code distribution: [400] 200 responses, which is the same status code response I get when I use Thunder Client and don`t pass the JSON body.

Does anyone know what I am doing wrong?

@hatoo
Copy link
Owner

hatoo commented Sep 22, 2023

You should try just putting a JSON to -d option

Such like

oha -n 1 -T application/json -d '{"code": "7843.92.73"}' http://localhost:8888
$ nc -l -p 8888
GET / HTTP/1.1
accept: */*
accept-encoding: gzip, compress, deflate, br
host: localhost:8888
user-agent: oha/0.6.3
content-type: application/json
content-length: 22

{"code": "7843.92.73"}

I think this request is what you want.

@ViniciusLucchesi
Copy link
Author

Thanks @hatoo, it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants