I’ve tested my REST API via Postman and tests and got a response, but when I use curl I’m getting
JavaScript
x
9
1
***@*** MINGW64 ~
2
$ curl http://localhost:80/api/v1/stats
3
% Total % Received % Xferd Average Speed Time Time Time Current
4
Dload Upload Total Spent Left Speed
5
100 267 100 267 0 0 1197 0 --:--:-- --:--:-- --:--:-- 1197<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
6
<title>Redirecting</title>
7
<h1>Redirecting</h1>
8
<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.
9
screen from postman enter image description here
the code:
app.py
JavaScript
1
5
1
app = Flask(__name__)
2
3
app.register_blueprint(attack_bp, url_prefix=URL_PATH + '/attack')
4
app.register_blueprint(stats_bp, url_prefix=URL_PATH + '/stats')
5
route.py
JavaScript
1
5
1
from flask import Blueprint
2
from controllers.Stats import index
3
stats_bp = Blueprint('stats_bp', __name__)
4
stats_bp.route('/', methods=['GET'])(index)
5
controller.py
JavaScript
1
8
1
from services import Services
2
3
s = Services()
4
5
6
def index():
7
return {"data": s.getStats()}
8
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