这是在Python中编写POST函数的正确方法吗?

时间:2010-12-19 12:58:12

标签: python http post

def URLRequest(url, params, method="POST"):
    h = Http()
    res, content = h.request(url, method, urllib.urlencode(params))
    r = {}
    r['res'] = res
    r['content'] = content
    return r

假设我想将{"key":"value"}发送到网址(REST)。这个功能是正确的吗?

1 个答案:

答案 0 :(得分:2)

如果有效则是正确的。你可以缩短它:

def URLRequest(url, params, method="POST"):
    res, content = Http().request(url, method, urllib.urlencode(params))
    return {'res':res, 'content':content}