Skip to content
Advertisement

curl getting redirect instead of response

I’ve tested my REST API via Postman and tests and got a response, but when I use curl I’m getting

***@*** 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.

screen from postman enter image description here

the code:

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()}

Advertisement

Answer

By default curl doesn’t follow redirection, you have to use -L argument.

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.

Source: https://everything.curl.dev/http/redirects#tell-curl-to-follow-redirects

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement