python2 httplib 笔记
python2 httplib 笔记
#coding=utf-8
'''
Created on 2014年9月25日 @author: cocoajin
''' import httplib,urllib base='httpbin.org' #不需要添加 "http://"
con=httplib.HTTPConnection(base)
ip = '/ip'
con.request('GET',ip)
re=con.getresponse()
print re.getheaders()
print re.read()
con.close() #GET
con=httplib.HTTPConnection(base)
parm={'name':'nick','age':18}
gets='/get'
con.request('GET', gets+'?'+urllib.urlencode(parm))
re=con.getresponse()
print re.getheaders()
print re.read()
con.close() #POST
con=httplib.HTTPConnection(base)
parm={'name':'nick','age':18}
posts='/post'
#headers = {"Content-type":"application/json","Accept":"text/plain"} json
headers = {"Content-type":"application/json","Accept":"text/plain"} #form
con.request('POST', posts,urllib.urlencode(parm),headers)
re=con.getresponse()
print re.getheaders()
print re.read()
con.close() #文件上传使用 "multipart/form-data"
python2 httplib 笔记的更多相关文章
- python2 urllib 笔记
python2 urllib 笔记 import urllib base='http://httpbin.org/' ip=base+'ip' r=urllib.urlopen(ip) print r ...
- Effective Python2 读书笔记1
Item 2: Follow the PEP 8 Style Guide Naming Naming functions, variables, attributes lowercase_unders ...
- 回味Python2.7——笔记4
一.Python 标准库概览 1.操作系统接口 os 模块提供了很多与操作系统交互的函数: >>> import os >>> os.getcwd() # Retu ...
- Effective Python2 读书笔记3
Item 22: Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples For example, say you wa ...
- Effective Python2 读书笔记2
Item 14: Prefer Exceptions to Returning None Functions that returns None to indicate special meaning ...
- 回味Python2.7——笔记3
一.错误和异常 1.异常处理 >>> while True: ... try: ... x = int(raw_input("Please enter a number: ...
- 回味Python2.7——笔记2
一.模块 模块是包括 Python 定义和声明的文件.文件名就是模块名加上 .py 后缀.模块的模块名(做为一个字符串)可以由全局变量 __name__ 得到. 1. 模块可以导入其他的模块. 一个( ...
- 回味Python2.7——笔记1
一.基本知识 1.一个值可以同时赋给几个变量: >>> x = y = z = 0 # Zero x, y and z >>> x 0 >>> y ...
- Python2.7笔记——常用技术点汇总
目录 · 概况 · 安装 · 基础 · 基础语法 · 数据类型 · 变量 · 常量 · 字符编码 · 字符串格式化 · list · tuple · dict · set · if语句 · for语句 ...
随机推荐
- 2016CCPC东北地区大学生程序设计竞赛 1008 HDU5929
链接http://acm.hdu.edu.cn/showproblem.php?pid=5929 题意:给你一种数据结构以及操作,和一种位运算,最后询问:从'栈'顶到低的运算顺序结果是多少 解法:根据 ...
- ArrayList,Vector,HashMap,HashSet,HashTable之间的区别与联系
在编写java程序中,我们最常用的除了八种基本数据类型,String对象外还有一个集合类,在我们的的程序中到处充斥着集合类的身影!java中集合大家族的成员实在是太丰富了,有常用的ArrayList. ...
- 2016年11月1日 星期二 --出埃及记 Exodus 19:17
2016年11月1日 星期二 --出埃及记 Exodus 19:17 Then Moses led the people out of the camp to meet with God, and t ...
- 集合、ArrayList 集合。Stack集合。Queue集合。以及Hashtable集合
arrayList 首先复制Colections加 : 创建arrayList ar =new arrayList(); //ArrayList al=new ArrayList(); ...
- C# Eval()和Bind()
Eval( " ")和Bind( " ") 这两种一个单向绑定,一个双向绑定,bind是双向绑定,但需数据源支持ASP.NET 2.0改善了模板中的数据绑定 ...
- BZOJ 1413 取石子游戏(DP)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1413 题意:n堆石子排成一排.每次只能在两侧的两堆中选择一堆拿.至少拿一个.谁不能操作谁 ...
- XML文件解析DOM解析和SAX解析
解析一个XML文档有哪些内容解析有:dom和sax两种dom:把整个XML文档放入内存,适合XML随机访问,占用内存资源大sax:事件驱动型的XML解析方式,顺序读取,不用一次装载整个文件,遇到标签会 ...
- Oracle同义词学习
oracle的同义词总结 从字面上理解就是别名的意思,和视图的功能类似.就是一种映射关系. 同义词拥有如下好处: 节省大量的数据库空间,对不同用户的操作同一张表没有多少差别; 扩展的数 ...
- ServiceStack.OrmLite 笔记4 删
删除 db.DeleteAll(); //各种姿势 db.Delete(p => p.Age == 27);// db.Delete(q => q.Where(p => p.Age ...
- Mybatis Generator(定制化)代码生成器
1.使用Mapper专用的MyBatis Generator插件 通用Mapper在1.0.0版本的时候增加了MyBatis Generator(以下简称MBG)插件,使用该插件可以很方便的生成实体类 ...