from request.parse import urlencode
data = {"user": "jähn", "id": 3} # note, a Python dictionary, not a JSON string
parameters = urlencode(data)
response = urllib.request.urlopen('?'.join((self.update_url, parameters)))
不要使用data参数;使用该关键字参数会强制请求使用POST方法:
data must be a bytes object specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format.
不能使用JSON编码的主体来发出GET请求,因为GET请求只由URL和头组成。参数是使用URL编码编码编码到URL中的,因此没有将这些参数编码为JSON的选项。在
使用^{} function 创建URL编码的参数,然后用
?
附加到URL。在不要使用
data
参数;使用该关键字参数会强制请求使用POST方法:相关问题 更多 >
编程相关推荐