获取重定向而不是响应

2024-04-19 11:29:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经通过Postman和tests测试了我的restapi,并得到了响应,但是当我使用curl时,我得到了

***@*** MINGW64 ~
$ curl http://localhost:80/api/v1/stats
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   267  100   267    0     0   1197      0 --:--:-- --:--:-- --:--:--  1197<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="http://localhost/api/v1/stats/">http://localhost/api/v1/stats/</a>.  If not click the link.

邮递员筛选 enter image description here

守则:

app.py

app = Flask(__name__)

app.register_blueprint(attack_bp, url_prefix=URL_PATH + '/attack')
app.register_blueprint(stats_bp, url_prefix=URL_PATH + '/stats')

route.py

from flask import Blueprint
from controllers.Stats import index
stats_bp = Blueprint('stats_bp', __name__)
stats_bp.route('/', methods=['GET'])(index)

controller.py

from services import Services

s = Services()


def index():
    return {"data": s.getStats()}

1条回答
网友
1楼 · 发布于 2024-04-19 11:29:56

默认情况下curl不遵循重定向,必须使用-L参数

In curl's tradition of only doing the basics unless you tell it differently, it does not follow HTTP redirects by default. Use the -L, location to tell it to do that.

资料来源:https://everything.curl.dev/http/redirects#tell-curl-to-follow-redirects

相关问题 更多 >