【问题标题】:Why doesn't the encoded 'slash' work as expected in restful api?为什么编码的“斜线”在restful api中不能按预期工作?
【发布时间】:2019-09-20 14:45:07
【问题描述】:

我有一个这样的 api 请求:

http://0.0.0.0:4000/sentence=SUITS/Test。

它在浏览器中出现错误:

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

然后我对“SUITS/Test。”进行 URL 编码:

http://0.0.0.0:4000/sentence=SUITS%2FTest

这给出了同样的错误信息。

如果我从 URL 中删除“/”,它就可以正常工作。

为什么 URL 编码在这里不起作用?

这是带有flask_restful的python restful api。

【问题讨论】:

    标签: rest flask-restful


    【解决方案1】:

    如果您在 Test 之前提供“/”,它会将“Test”视为资源,然后在这种情况下,“sentence”应被视为在“?”之后作为 GET 有效负载传递的查询参数喜欢:

    http://0.0.0.0:4000/Test?sentence=SUITS

    【讨论】:

    • 那么问题是如何使用'/'正确获取这个URL?
    • 我使用了“%2F”的 URL 编码,但仍然显示 URL 未找到。
    猜你喜欢
    • 1970-01-01
    • 2017-06-08
    • 2021-05-09
    • 2021-05-30
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多