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语句 ...
随机推荐
- C语言中'\0'与'\n'
'\0'表示ASCII编号为0的字符,在C语言中最常用于代表字符串结束的标志.'\n'表示ASCII编号为13的字符,代表回车键,输出这个字符就会换一行. '\0'作为字符串的结束标志,本身会占用一个 ...
- html之a标签
屏蔽跳转 1.href属性删除 2.href="javascript:void(0);" void是一个操作符,void(0)返回undefined,地址不发生跳转. 3.s ...
- Apache-Shiro+Zookeeper系统集群安全解决方案之缓存管理
上篇[Apache-Shiro+Zookeeper系统集群安全解决方案之会话管理],解决了Shiro在系统集群开发时安全的会话共享问题,系统在使用过程中会有大量的权限检查和用户身份检验动作,为了不频繁 ...
- Monocular Vision
Monocular Vision: a condition in which one eye is blind, seeing with only one eye Binocular Vision: ...
- splay学习
今天学习了一下spaly..... 感觉除了比较难打,比较难调,但还是很好理解的啊.... 1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: ...
- linux软件下载及安装
1.jdk安装以及下载地址 rpm.tar.gz格式下载 | bin格式下载 官方bin格式下载 | 安装 2.centos安装phpstorm 戳我
- 工具配置(eclipse/plsql)
PLSQL 附常用配置: PrefAutomaticStatistics=True SelectedStatNames= AutoSelectSQL=True ShowSQLWindowGutte ...
- 【转】分析Linux和windows动态库
原文地址:http://www.cnblogs.com/chio/archive/2008/11/13/1333119.html 摘要:动态链接库技术实现和设计程序常用的技术,在Windows和Lin ...
- mysql 1030 Got error 28 from storage engine
mysql 1030 Got error 28 from storage engine 错误原因:磁盘临时空间不够. 解决办法:df -h 查看设备存储的使用情况 du -h --max-depth= ...
- 无限极分类,传递一个子ID得到所有父集,用于在前台分层显示标题
方法: static public function getParents($data,$id){ $arr=array(); foreach ($data as $v) { if ($v['id'] ...