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 笔记的更多相关文章

  1. python2 urllib 笔记

    python2 urllib 笔记 import urllib base='http://httpbin.org/' ip=base+'ip' r=urllib.urlopen(ip) print r ...

  2. Effective Python2 读书笔记1

    Item 2: Follow the PEP 8 Style Guide Naming Naming functions, variables, attributes lowercase_unders ...

  3. 回味Python2.7——笔记4

    一.Python 标准库概览 1.操作系统接口 os 模块提供了很多与操作系统交互的函数: >>> import os >>> os.getcwd() # Retu ...

  4. Effective Python2 读书笔记3

    Item 22: Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples For example, say you wa ...

  5. Effective Python2 读书笔记2

    Item 14: Prefer Exceptions to Returning None Functions that returns None to indicate special meaning ...

  6. 回味Python2.7——笔记3

    一.错误和异常 1.异常处理 >>> while True: ... try: ... x = int(raw_input("Please enter a number: ...

  7. 回味Python2.7——笔记2

    一.模块 模块是包括 Python 定义和声明的文件.文件名就是模块名加上 .py 后缀.模块的模块名(做为一个字符串)可以由全局变量 __name__ 得到. 1. 模块可以导入其他的模块. 一个( ...

  8. 回味Python2.7——笔记1

    一.基本知识 1.一个值可以同时赋给几个变量: >>> x = y = z = 0 # Zero x, y and z >>> x 0 >>> y ...

  9. Python2.7笔记——常用技术点汇总

    目录 · 概况 · 安装 · 基础 · 基础语法 · 数据类型 · 变量 · 常量 · 字符编码 · 字符串格式化 · list · tuple · dict · set · if语句 · for语句 ...

随机推荐

  1. NSIS学习记录の----NSIS多语言安装以及详解

    NSIS多语言安装,很多教程提供了详细的代码,但是代码中某些语句的含义我还是不很明白,作为一个吃螃蟹的人,我做一个解释,避免很多小伙伴和我哟U一样的误区,以下结论都是自己根据实践得来,若发现理解错误, ...

  2. 2016年7月2日 星期六 --出埃及记 Exodus 14:29

    2016年7月2日 星期六 --出埃及记 Exodus 14:29 But the Israelites went through the sea on dry ground, with a wall ...

  3. Linux基本配置

    Linux发行版:centos 6.5 配置yum源 wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -P /etc/yum.repos ...

  4. linux中的shell脚本编程

    [1]shell脚本 1--- shell命令 2--- 控制语句(新的语法) (Shell命令的有序集合) [2]创建shell脚本文件 1--- 1.sh 2--- chmod 777 1.sh ...

  5. .Net大文件上传(转--待验证)

    几种常见的方法,本文主要内容包括:    第一部分:首先我们来说一下如何解决ASP.net中的文件上传大小限制的问题,我们知道在默认情况下ASP.NET的文件上传大小限制为2M,一般情况下,我们可以采 ...

  6. Web开发——Tomcat的配置

    1.选择Tomcat 1.Apache官网http://apache.org/ 2.Tomcat官网http://tomcat.apache.org/ 3.Tomcat下载地址http://tomca ...

  7. javascript权威指南笔记--javascript语言核心(一)

    1.javascript的数据类型分为两类:原始类型和对象类型. 原始类型包括字符串.数字.布尔值.null.undefined. 对象是属性的集合,每个对象都由“名/值”对构成.数组和函数是特殊的对 ...

  8. window.location.hash

    我们知道JavaScript中很早就提供了window.history对象,利用history对象的forward().go().back()方法能够方便实现不同页面之间的前进.后退等这种导航功能.但 ...

  9. iOS - UISwitch

    前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UISwitch : UIControl <NSCoding> @a ...

  10. LCM兼容

    1.project-1998-trunk-bootable-bootloader-lk-project:   复制zaw1998aa_platform.mk为zaw2000aa_platform.mk ...