如何将HTTP请求发送到Flask服务器 [英] How to send http requests to flask server

查看:534
本文介绍了如何将HTTP请求发送到Flask服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的烧瓶应用程序启动时,它会显示

When my flask application is started, it says

Running on http://0.0.0.0:80/

如何向该服务器发送http请求?

How do I send http requests to this server?

我尝试了

telnet 0.0.0.0 80

但是它说:

Trying 0.0.0.0...
telnet: connect to address 0.0.0.0: Invalid argument

我使用了请求模块:

r = requests.get('http://0.0.0.0:80')

结果相同

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 288, in request
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 383, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 206, in send
    raise ConnectionError(sockerr)
requests.exceptions.ConnectionError: [Errno 22] Invalid argument

netstat的输出如下:

The output of netstat is given below:

# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:http            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:domain          0.0.0.0:*               LISTEN
tcp6       0      0 [::]:domain             [::]:*                  LISTEN
udp        0      0 0.0.0.0:domain          0.0.0.0:*
udp        0      0 0.0.0.0:bootps          0.0.0.0:*
udp6       0      0 [::]:domain             [::]:*

推荐答案

0.0.0.0表示本地计算机上的所有IPv4地址".这是一个不可路由的元地址.

0.0.0.0 means "all IPv4 addresses on the local machine". It is a meta-address which is non-routable.

如果要本地访问服务器,即与服务器位于同一台计算机上的客户端,请使用IP地址127.0.0.1(环回Internet协议)或等效的域名(本地主机)

If you want to access the server locally, i.e. client on the same machine as the server, either use the IP address 127.0.0.1 (loopback Internet protocol) or the equivalent named domain name (localhost)

r = requests.get('http://127.0.0.1:80')
r = requests.get('http://localhost:80')

如果要从远程计算机(在同一子网上)访问服务器,则可以通过运行服务的服务器IP地址(由路由器/网关分配)连接到服务器

If you are accessing the server from a remote machine (on the same subnet), you can connect to your server through the IP address of server (assigned by your router/gateway) running your service

如果要从远程计算机访问服务器,则可以通过路由器的IP地址连接到服务器.您需要通过适当的端口转发来设置虚拟服务器.

If you are accessing the server from a remote machine otherwise, you can connect to your server through the IP address of your router. You need to set up Virtual servers by appropriate port forwarding.

这篇关于如何将HTTP请求发送到Flask服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆