python2学习笔记之查看API接口、http的使用

__author__ = 'Administrator'
#encoding=utf-8
from ctypes import *
msvcrt=cdll.msvcrt
message_str="hello word\n"
#msvcrt.dll的导出函数
msvcrt.printf("Testing %s",message_str);
#学习新的ctypes库 先查看API接口,可以 开始->所有程序->python 2.xx->Module Docs

s=create_string_buffer(100);
msvcrt.sprintf(s,"Hello %s\n","hehe");
print(s.value.decode("utf-8"))

class A:
    def a(self):
        pass
    def b(self):
        pass

#查看API接口
print(dir(msvcrt))
print(help(msvcrt))
import sys
print(help(sys.argv))
print(help(A))
print(dir(A))

import platform
print(platform.python_version())
print(platform.uname())
#python demo https://docs.python.org/2/tutorial/index.html
import os
print(os.listdir("d:/"))
os.system("notepad %s"% "hehe".decode("utf-8"))
__author__ = 'Administrator'
#coding=utf-8
'''
import httplib
conn=httplib.HTTPConnection("www.qq.com")
conn.request('get',"/")
print(conn.getresponse().read())
conn.close()
'''

#http://blog.csdn.net/JGood/article/details/4317416
#coding=gbk
import httplib
conn = httplib.HTTPConnection("www.qq.com", 80, False)
conn.request('get', '/', headers = {"Host": "www.google.cn",
                                    "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1) Gecko/20090624 Firefox/3.5",
                                    "Accept": "text/plain"})
res = conn.getresponse()
print 'version:', res.version
print 'reason:', res.reason
print 'status:', res.status
print 'msg:', res.msg
print 'headers:', res.getheaders()
#html
#print '/n' + '-' * 50 + '/n'
print (res.read())
conn.close()


#http://www.oschina.net/code/snippet_54100_7485
#get
conn = httplib.HTTPSConnection("www.python.org")
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
conn.request("GET", "/parrot.spam")
r2 = conn.getresponse()
print r2.status, r2.reason
#data2 = r2.read()
#print(data2)
conn.close()

#head
conn = httplib.HTTPSConnection("www.python.org")
conn.request("HEAD","/index.html")
res = conn.getresponse()
print res.status, res.reason
data = res.read()
print len(data)
#post


import urllib
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = httplib.HTTPConnection("www.baidu.com:80")
conn.request("POST", "/cgi-bin/query", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print(data)
conn.close()
#http://www.open-open.com/lib/view/open1385890658814.html


你可能感兴趣的:(python2学习笔记之查看API接口、http的使用)