Skip to content

Instantly share code, notes, and snippets.

@hujj0615
Created December 4, 2012 07:12
Show Gist options
  • Save hujj0615/4201456 to your computer and use it in GitHub Desktop.
Save hujj0615/4201456 to your computer and use it in GitHub Desktop.
python urllib http post exapmle
import urllib
url = "http://localhost:8080/test"
def postNews(title, source, category, content):#gbk encoding
params=urllib.urlencode({"title":title, "source":source, "category":category, "content":content})
resp = urllib.urlopen(url, params)
print resp.readlines()
resp.close()
if __name__ == '__main__':
title = "标题"
source = "来源"
category = "新闻"
content = "内容123"
title = unicode(title,'utf-8').encode('gbk')
source = unicode(source,'utf-8').encode('gbk')
category = unicode(category,'utf-8').encode('gbk')
content = unicode(content,'utf-8').encode('gbk')
postNews(title, source, category, content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment