当urlopen中data为None或不写时,此时为GET;

当data不为None时,此时为POST

from urllib import request,parse
import json

url = 'http://192.168.10.1/api.php'
req = request.Request(url)
data = parse.urlencode({'c':'get_equipment_list',
                        'token':'9b90b4accacfe148d820f242ce19b294'})
res = request.urlopen(req, data=data.encode('utf-8'))
data = res.read()
out = json.loads(data)

urlopen中传递data值时,此时为post,通过wireshark捕获如下:

 

python学习之 urllib的post与get

 

 

from urllib import request,parse
import json

url = 'http://192.168.10.1/api.php'
req = request.Request(url)

res = request.urlopen(req, data=None)
data = res.read()
out = json.loads(data)

python学习之 urllib的post与get

相关文章:

  • 2021-11-13
  • 2021-12-08
  • 2021-06-16
  • 2022-12-23
  • 2021-06-04
  • 2021-09-25
  • 2022-02-28
猜你喜欢
  • 2021-09-16
  • 2021-04-12
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案