来自Python的URL请求 [英] URL request from Python
本文介绍了来自Python的URL请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个正在运行的服务器,它始终在监听value
字段
我可以从Web浏览器通过URL发出请求,
I have a Server running and its always listening to the value
field
I can make a requests from a web browser from the URL,
Eg: http://192.168.1.101/value=1
我如何从Python发出这样的请求,我尝试了上面的代码,但似乎不起作用.
How can i make a request like this from Python, i tried the above code but it doesnt seem to work.
from urllib.parse import urlencode
from urllib.request import Request, urlopen
url = 'http://192.168.1.101/value=1'
request = Request(url)
我的服务器正在监听上述格式.(GET)
My server is listening in the above formate.(GET)
GET /value=1 HTTP/1.1
干杯!
推荐答案
使用请求模块
import requests as req
url = 'http://192.168.1.101/value=1'
resp = req.get(url)
print(resp.text) # Printing response
这篇关于来自Python的URL请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文