Accessing URL from Chrome and Safari goes well but terminal encounters `curl: (52) Empty reply from server`, what do I do? This python flask code hosts a simple web service
app = Flask(__name__)

@app.route('/login', methods=['POST', 'GET'])
def login():
    if request.method == 'POST':
        user = request.form['nm']
        print(user)
        return redirect(url_for('user', usr=user))
    else:
        return render_template('login.html')

@app.route('/&lt;usr&gt;')
def user(usr):
    return f'{usr}'

if __name__ == &quot;__main__&quot;:
    app.run(host=&quot;0.0.0.0&quot;)

Here is the login.html
&lt;form action=&quot;#&quot; method=&quot;post&quot;&gt;
    &lt;p&gt;&lt;input type=&quot;text&quot; name=&quot;nm&quot; id=&quot;&quot;&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;submit&quot;&gt;&lt;/p&gt;
&lt;/form&gt;

My Mac's IP = 192.168.31.37
When I access the following URL from Chrome and Safari
http://192.168.31.37:5000/aa

everything goes as expected.
However, when I run this line from terminal
$ curl http://192.168.31.37:5000/aa

I always get this
curl: (52) Empty reply from server

I looked into a post but got no clue for this. What do I do?
not just this URL, curl in the terminal on my Mac gives this error for any URL.
The content you get from a server doesn't just depend on the URL. It can depend on the request method, the language preferences, user agent, cookies, etc.
You can ask your browser exactly what it sends to the server. Chrome, Firefox and Safari all have a command in their developer tools which copies something to the clipboard that you can paste in a shell window. In Safari, enable developer tools and open the Web Inspector on the current page. In Chrome or Firefox, press F12. In any of these browsers, in the developer tools, go to the Network tab, reload the page, select the first location and “Copy as cURL” from the context menu (it may be in a “Copy” submenu). Then paste the command in a terminal. The command will have the form
curl -X GET -H … http://192.168.31.37:5000/aa

Your curl command doesn't specify a method, so it's a GET by default. The form specifies a POST. So if you're trying to simulate entering the form, you'll need to pass -X POST to curl, and of course to pass the form data. To see what the browser sends with the form, open the developer tools' and switch to the ”Network“ tab before submitting the form, then use the “copy as cURL” command from the form URL.