Created
December 4, 2012 07:12
-
-
Save hujj0615/4201456 to your computer and use it in GitHub Desktop.
python urllib http post exapmle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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