使用PYTHON脚本获取请求

2024-04-20 10:12:11 发布

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

我有以下问题。你知道吗

我在tomcat9上部署了REST服务,我可以通过浏览器发送请求。 例如

http://localhost:8080/my_app/ping

给我期望的“Hello world”字符串。你知道吗

现在,我尝试通过Python脚本发送相同的GET请求:

import requests
r = requests.get('http://localhost:8080/my_app/ping')
print(r.content)

接收

"HTTP Status 404 – Not Found" ... "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists".

我怎样才能解决这个问题? 谢谢

附加:相同的行为使用卷曲


Tags: 字符串脚本restapplocalhosthttphelloworld