转自:http://pnig0s1992.blog.51cto.com/393390/454576
httplib request的用法
getresponse() 用以进行返回数据
看下面的列子:
#!/usr/bin/python
#-*-coding:utf-8-*-
# 进行表单提交 小项 2008-10-09
import httplib,urllib; #加载模块
#定义需要进行发送的数据
params = urllib.urlencode({'cat_id':'6',
'news_title':'标题-Test39875',
'news_author':'Mobedu',
'news_ahome':'来源',
'tjuser':'carchanging',
'news_keyword':'|',
'news_content':'测试-Content',
'action':'newnew',
'MM_insert':'true'});
#定义一些文件头
headers = {"Content-Type":"application/x-www-form-urlencoded",
"Connection":"Keep-Alive","Referer":""};
#与网站构建一个连接
conn = httplib.HTTPConnection("192.168.1.212");
#开始进行数据提交 同时也可以使用get进行
conn.request(method="POST",url="/newsadd.asp?action=newnew",body=params,headers=headers);
#返回处理后的数据
response = conn.getresponse();
#判断是否提交成功
if response.status == 302:
print "发布成功!^_^!";
else:
print "发布失败\^0^/";
#关闭连接
conn.close();
阅读(1159) | 评论(0) | 转发(0) |