url='https://www.propertyvalue.com.au/?op=myrp_widgets.freemiumInvestorSLAS.singleLineSearchHandler&subop=getSuggestionList&searchCategories=1%2C2%2C3%2C4&searchString=3%20taggerty%20street%20ngunnawal&maxSuggestionResults=5&_=1490747216388'

header={'Content-Type':'text/html','User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0'}

req=requests.get(url,headers=header,stream=True)

print(req.headers)

print(req.content)

print(req.text)

url='http://baike.baidu.com/item/ssl'

req=requests.get(url,stream=True)

c=req.content

type(c)

print(c.decode('utf-8'))

"""
Explanation: 这里stream=True的好处是，它首先只下载headers,直到我们调用req.content才去下载网页的内容
End of explanation
"""


with open('massive-body', 'rb') as file:    
    requests.post('http://example.com/some/stream/url',data=file)

"""
Explanation: A file-like object which is of massive size can be streamed and uploaded using the Requests library. All we need to do is to supply the contents of the stream as a value to the data attribute in the request call as shown in the following lines.
End of explanation
"""


def generator():
    yield '1st data'.encode('utf-8')
    yield '2nd data'.encode('utf-8')
    yield '3rd data'.encode('utf-8')
    yield '4th data'.encode('utf-8')
    yield 'last data'.encode('utf-8')

url='http://httpbin.org'

req=requests.post(url+'/post',data=generator())

print(req.content)

req=requests.post(url+'/post',data='1st data'.encode('utf-8'))

print(req.text)

import json

req=requests.get(url+'/stream/4',stream=True)

print(req.headers)

c=req.content

type(c)

d=c.decode('utf-8')

data=json.load(c)

e={'1':1,'2':2}

e_j=json.dumps(e)

print(e_j)

e_d=json.loads(e_j)

print(e_d)

url='http://www.chnaus.com/forum-house-5.html'

req=requests.head(url=url,headers=header)

print(req.headers)

h=req.headers

print(h.keys)

"""
Explanation: 看不出任何用处
End of explanation
"""


