python发送HTTP GET请求
来源:互联网 发布:nginx搭建web服务器 编辑:程序博客网 时间:2024/05/20 06:10
最近做的一个模块里需要发送GET请求,带参数的,查了网上很多例子,以及官方文档,都没交代清楚要如何做,大部分都是直接请求了一个页面。官方例子里,只有post请求是比较详细的。没办法,只好自己动手做实验了。现在把实验结果总结如下:
1.通过 httplib模块
conn = httplib.HTTPConnection(Addr,timeout=7) url=/game/user/info?id=28 conn.request("GET",url) conn.request("GET",url,'',headers) response = conn.getresponse() Data=response.read()
这里有必要提一下request的定义:
def request(self, method, url, body=None, headers={}):
"""Send a complete request to the server."""
try:
self._send_request(method, url, body, headers)
except socket.error, v:
# trap 'Broken pipe' if we're allowed to automatically reconnect
if v.args[0] != 32 or not self.auto_open:
raise
# try one more time
self._send_request(method, url, body, headers)
对于GET请求来说,因为参数已经带在url里,body是空的,而对于POST来说,body就是发送出去的参数了。
2.通过urllib2
url=/game/user/info?id=28
full_url='http://192.168.1.250'+url.
data=urllib2.urlopen(full_url)
Data=data.read()
- python发送HTTP GET请求
- python发送HTTP GET请求
- Python发送HTTP GET请求
- python发送get请求
- lua发送http get请求
- http协议get发送请求
- HTTP 发送get post请求
- http发送get、post请求
- Http发送GET/POST请求
- HTTP URLConnection 发送get请求
- python发送HTTP请求
- python发送HTTP请求
- python发送HTTP请求
- python发送http请求
- python 发送http请求
- python发送HTTP请求
- JAVA 发送Http请求,GET、POST请求
- Python发送get,post请求
- Android ApiDemos示例解析(24):App->Launcher Shortcuts
- Xcode 4.1~4.6 + iOS 5、iOS 6免证书(iDP)开发+真机调试+生成IPA全攻略
- #define 的妙用
- Word,Excel大小写批量转换
- Java Swing编程
- python发送HTTP GET请求
- Web Service学习笔记
- C#调用Exe方法+实例分析
- wordpress杂记
- cocos2d-x ios工程路径问题
- CASE在sql server中的使用用法
- UNIX中的文件和目录
- poj 1703 Find them, Catch them(并查集应用)
- android学习之绘图总结