Is this the right way to write a POST function in Python?
def URLRequest(url, params, method="POST"):
h = Http()
res, content = h.request(url, method开发者_如何学Go, urllib.urlencode(params))
r = {}
r['res'] = res
r['content'] = content
return r
Suppose I want to POST {"key":"value"}
to a url (REST). Is this function the right way to do it?
If it works it is correct. You can make it shorter though:
def URLRequest(url, params, method="POST"):
res, content = Http().request(url, method, urllib.urlencode(params))
return {'res':res, 'content':content}
精彩评论