我有一个服务器正在运行,它总是在侦听该value字段,
我可以从 URL 的 Web 浏览器发出请求,
Eg: http://192.168.1.101/value=1
Run Code Online (Sandbox Code Playgroud)
我如何从 Python 发出这样的请求,我尝试了上面的代码,但它似乎不起作用。
from urllib.parse import urlencode
from urllib.request import Request, urlopen
url = 'http://192.168.1.101/value=1'
request = Request(url)
Run Code Online (Sandbox Code Playgroud)
我的服务器正在侦听上述格式。(GET)
GET /value=1 HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
干杯!
使用请求模块
import requests as req
url = 'http://192.168.1.101/value=1'
resp = req.get(url)
print(resp.text) # Printing response
Run Code Online (Sandbox Code Playgroud)