14.3.1 发送GET请求
import urllib.request
url = 'http://localhost:8000/NoteWebService/note.do?/action=query&ID=10'
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as response:
data = response.read()
json_data = data.decode()
print(json_data)
14.3.2 发送POST请求
import urllib.request
url = 'http://localhost:8080/NoteWebService/note.do'
params_dict = {'action':'query','ID':'10'}
params_str = urllib.parse.urlencode(params_dict)
print(params_str)
params_bytes = params_str.encode()
req = urllib.request.Request(url,data = params_bytes) #
with urllib.request.urlopen(req) as response:
data = response.read()
json_data = data.decode()
print(json_data)
14.4.2 JSON数据的解码
import urllib.request
import json
url = 'http://localhost:8000/NoteWebService/note.do?/action=query&ID=10'
req = urllib.request.Request(url)
wit

本文通过漫画形式讲解了Python中如何进行网络请求,包括GET和POST方式,还介绍了JSON数据的解码,并给出了下载图片的示例,以及如何获取所有备忘录信息。

602

被折叠的 条评论
为什么被折叠?



