PySpider/showHeaders.py

 

<?php
//D:\workspace\php\hellophp\login\show_headers.php
header("Content-type: text/html; charset=utf-8");
$arry_headers=getallheaders();
print_r($arry_headers);
?>
import urllib
import urllib2

url = "http://localhost/hellophp/login/show_headers.php"
values = {}
values['username'] = "1016903103@qq.com"
values['password'] = "PPPPSSSSWWWWDDDD"
data = urllib.urlencode(values)

user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = {'User-Agent': user_agent, 'Jim':'Green'}
headers['hello']="world!"

request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
page = response.read()
print page
C:\Python27\python.exe D:/PycharmProjects/PySpider/showHeaders.py
Array
(
    [Accept-Encoding] => identity
    [Content-Length] => 54
    [Jim] => Green
    [Connection] => close
    [User-Agent] => Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)
    [Host] => localhost
    [Content-Type] => application/x-www-form-urlencoded
    [Hello] => world!
)

 

posted @ 2018-01-07 15:27  sky20080101  阅读(87)  评论(0)    收藏  举报