python使用自带模块httplib进行http请求
#-*- encoding:utf-8 -*-
import httplib, time class httpRequest():
def __init__(self, headers, requestUrl, requestParam):
self.headers = headers
self.requestUrl = requestUrl
self.requestParam = requestParam def httpRequestPost(self):
conn=httplib.HTTPConnection(host=requestUrl.split("/")[2].split(":")[0], port=80, strict=False, timeout=30)
conn.request(method='POST',url=requestUrl.split(requestUrl.split("/")[2])[1], body=self.requestParam, headers=self.headers)
result = conn.getresponse().read()
print result if __name__ == "__main__":
headers = {"Content-Type" : "application/json"}
requestUrl = "http://domain/context"
requestParam = '{"param1": "value1"}' conn = httpRequest(headers, requestUrl, requestParam)
conn.httpRequestPost()
python使用自带模块httplib进行http请求的更多相关文章
- Python 学习之urllib模块---用于发送网络请求,获取数据
1.urllib urllib是Python标准库的一部分,包含urllib.request,urllib.error,urllib.parse,urlli.robotparser四个子模块. (1) ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(5)
查询城市天气最后一节 需要导入上一节的结果city10.py #!/usr/bin/python# -*- coding: UTF-8 -*-import urllib.requestfrom ci ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(4)
承接将查询城市编码的结果保存到文件中,以字典的形式保存,目的是为了在查询某个城市的天气的时候,能够通过输入的城市名称,找到对应的城市编码.所以此结果字典的数据结构,就是city={城市名称:城市编码} ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(3)
上节内容,是得到了省/直辖市编码,如web='http://m.weather.com.cn/data5/city01',我们需要继续获取此接口的数据,于是进行下面的操作 for i in b ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(2)
接着上一次的内容. 先说明一下关于split()方法:它通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串(把一个字符串分割成很多字符串组成的list列表) 语法: ...
- Python内置模块和第三方模块
1.Python内置模块和第三方模块 内置模块: Python中,安装好了Python后,本身就带有的库,就叫做Python的内置的库. 内置模块,也被称为Python的标准库. Python 2.x ...
- Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 httplib模块 django和web服务器整合 wsgi模块 gunicorn模块
Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 ...
- 通过Python自带模块SimpleHTTPServer快速共享服务的配置文件
简介 SimpleHTTPServer是Python 2自带的一个模块,是Python的Web服务器,简单小巧,快速启动. 它在Python 3已经合并到http.server模块中. SimpleH ...
- python中urllib, urllib2,urllib3, httplib,httplib2, request的区别
permike原文python中urllib, urllib2,urllib3, httplib,httplib2, request的区别 若只使用python3.X, 下面可以不看了, 记住有个ur ...
随机推荐
- <转>python列表、元组、集合、字典、json相互转换以及其他基础入门
列表元组转其他 # 列表转集合(去重) list1 = [6, 7, 7, 8, 8, 9] set(list1) # {6, 7, 8, 9} #两个列表转字典 list1 = ['key1','k ...
- Shell 中eval的用法
test.sh:pipe="|"eval ls $pipe wc -l 输出bogon:Desktop macname$ ./test.sh 45 test.sh:eval ech ...
- lastal
http://last.cbrc.jp/doc/lastal.html This program finds local alignments between query sequences, and ...
- Android Sensor 架构深入剖析【转】
本文转载自: 1.Android sensor架构 Android4.0系统内置对传感器的支持达13种,它们分别是:加速度传感器 (accelerometer).磁力传感器(magnetic fiel ...
- yum -y install pip No package pip available. Error: Nothing to do
centos下安装pip时失败: [root@wfm ~]# yum -y install pipLoaded plugins: fastestmirror, refresh-packagekit, ...
- 在 Alpine Linux 中安装 bash shell
如何在我的 Alpine Linux LXD(Linux容器)虚拟机(VM)中安装 bash shell? Alpine Linux 自带 BusyBox 工具.它被评为“嵌入式 Linux 的瑞士军 ...
- 【JavaScript】JavaScript中的ActiveXObject对象
JavaScript中ActiveXObject对象是启用并返回 Automation 对象的引用. 使用方法: newObj = new ActiveXObject( servername.t ...
- java.lang.Exception: No tests found matching
java.lang.Exception: No tests found matching 需要导入junit.jar 和 hamcrest.jar
- Python3用多线程替代for循环提升程序运行速度
[本文出自天外归云的博客园] 优化前后新老代码如下: from git_tools.git_tool import get_collect_projects, QQNews_Git from thre ...
- weui.js汉字乱码
2019-6-25 11:04:13 星期二 min.js 源文件中会自带乱码: 鍙栨秷: 取消; 纭畾: 确定; 方案: 把weui.js用notepad++打开, 搜索乱码字符, 替换掉, ...