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

[BUG]can not get params by application/x-www-form-urlencoded #83

Closed
csy18 opened this issue Nov 18, 2020 · 4 comments
Closed

[BUG]can not get params by application/x-www-form-urlencoded #83

csy18 opened this issue Nov 18, 2020 · 4 comments

Comments

@csy18
Copy link

csy18 commented Nov 18, 2020

when frontend pass params using application/x-www-form-urlencoded, spectree can not get params by query, is there any other ways to get it?
截屏2020-11-18 上午10 42 59
截屏2020-11-18 上午10 48 06
截屏2020-11-18 上午10 48 24

I just find the code using request.args and request.json to get params, however request.values or request.form not use.
截屏2020-11-18 上午10 37 00

@kemingy
Copy link
Member

kemingy commented Nov 18, 2020

Thanks for your feedback.

When you use application/x-www-form-urlencoded, the data is in the body. This is different from call GET localhost:8000/?user=hello&msg=hello&index=1. That's why you cannot get it from the request.args.

But flask provides a request.form to support this behavior, which is not a very common. Instead, sending data in a JSON format with application/json is more general. Because usually the response is also in the JSON format.

In Postman, you should use form-data.

Back to this question, of course I can detect the content type and try to get data from request.form. But I guess in this way I should store it in json instead of query. (I know the name json is not very proper, because the data can be any type, check #53)

@csy18 csy18 closed this as completed Nov 18, 2020
@csy18 csy18 reopened this Nov 18, 2020
@csy18
Copy link
Author

csy18 commented Nov 18, 2020

Thanks for your reply.

When you use application/x-www-form-urlencoded, the data is in the body. This is different from call GET localhost:8000/?user=hello&msg=hello&index=1. That's why you cannot get it from the request.args.

But flask provides a request.form to support this behavior, which is not a very common. Instead, sending data in a JSON format with application/json is more general. Because usually the response is also in the JSON format.

In Postman, you should use form-data.

Back to this question, of course I can detect the content type and try to get data from request.form. But I guess in this way I should store it in json instead of query. (I know the name json is not very proper, because the data can be any type, check #53)

Thanks for your feedback.

When you use application/x-www-form-urlencoded, the data is in the body. This is different from call GET localhost:8000/?user=hello&msg=hello&index=1. That's why you cannot get it from the request.args.

But flask provides a request.form to support this behavior, which is not a very common. Instead, sending data in a JSON format with application/json is more general. Because usually the response is also in the JSON format.

In Postman, you should use form-data.

Back to this question, of course I can detect the content type and try to get data from request.form. But I guess in this way I should store it in json instead of query. (I know the name json is not very proper, because the data can be any type, check #53)

now I need to get params by application/x-www-form-urlencoded, but I can not get it by spectree, would you like to provide this function?

@kemingy
Copy link
Member

kemingy commented Nov 18, 2020

now I need to get params by application/x-www-form-urlencoded, but I can not get it by spectree, would you like to provide this function?

Yes, it's possible. I'll try to detect the content type. So if you use application/x-www-form-urlencoded, the data will be parsed and store in json.

Let me create a PR for this.

@kemingy
Copy link
Member

kemingy commented Nov 18, 2020

@csy18 try version 0.3.12

@kemingy kemingy closed this as completed Apr 1, 2021
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