python发送HTTP请求
来源:互联网 发布:mysql proxy sysbench 编辑:程序博客网 时间:2024/05/09 00:46
http://www.oschina.net/code/snippet_54100_7485
[代码] GET 方法
01
>>>
import
httplib
02
>>> conn
=
httplib.HTTPConnection(
"www.python.org"
)
03
>>> conn.request(
"GET"
,
"/index.html"
)
04
>>> r1
=
conn.getresponse()
05
>>>
print
r1.status, r1.reason
06
200
OK
07
>>> data1
=
r1.read()
08
>>> conn.request(
"GET"
,
"/parrot.spam"
)
09
>>> r2
=
conn.getresponse()
10
>>>
print
r2.status, r2.reason
11
404
Not Found
12
>>> data2
=
r2.read()
13
>>> conn.close()
[代码] HEAD 方法
01
>>>
import
httplib
02
>>> conn
=
httplib.HTTPConnection(
"www.python.org"
)
03
>>> conn.request(
"HEAD"
,
"/index.html"
)
04
>>> res
=
conn.getresponse()
05
>>>
print
res.status, res.reason
06
200
OK
07
>>> data
=
res.read()
08
>>>
print
len
(data)
09
0
10
>>> data
=
=
''
11
True
[代码] POST 方法
01
>>>
import
httplib, urllib
02
>>> params
=
urllib.urlencode({
'spam'
:
1
,
'eggs'
:
2
,
'bacon'
:
0
})
03
>>> headers
=
{
"Content-type"
:
"application/x-www-form-urlencoded"
,
04
...
"Accept"
:
"text/plain"
}
05
>>> conn
=
httplib.HTTPConnection(
"musi-cal.mojam.com:80"
)
06
>>> conn.request(
"POST"
,
"/cgi-bin/query"
, params, headers)
07
>>> response
=
conn.getresponse()
08
>>>
print
response.status, response.reason
09
200
OK
10
>>> data
=
response.read()
11
>>> conn.close()
- python发送HTTP请求
- python发送HTTP请求
- python发送HTTP请求
- python发送http请求
- python 发送http请求
- python发送HTTP请求
- python发送HTTP GET请求
- python发送HTTP GET请求
- Python发送HTTP GET请求
- 鉴客 python发送HTTP请求
- python 发送http post请求
- Python之使用Python发送HTTP请求
- Python发送HTTP请求工具包httplib
- Python发送HTTP请求工具包httplib
- 使用python发送http请求代码
- python发送http请求之requests模块
- python使用urllib2发送http请求
- Python发送带header的http请求
- 使用Xcode 4编译器设定Release/Debug教程
- interface接口
- vc++窗口的创建过程(MFC消息机制的经典文章)
- 单文档界面大小下限设置
- 在SAP系统中,对于曰币、韩币这类特殊货币的处理是有特殊规则
- python发送HTTP请求
- 如果经常性地死机或蓝屏一般就做以下处理
- 敢做就要敢认!
- mysql,sqlserver,oracle三种数据库的大对象存取
- ARM7---数码管显示---0-F
- Spring 注解
- 教程Xcode 4下编译发布与提交App到AppStore
- 查看蓝屏代码
- Ogre的renderScene代码