Python Proxy Test: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
(Created page with "<pre> #!/usr/bin/env python from base64 import b64encode import httplib import pprint pp = pprint.PrettyPrinter(indent=4) c = httplib.HTTPConnection('IPADDRESS:8080') userA...") |
No edit summary |
||
Line 7: | Line 7: | ||
pp = pprint.PrettyPrinter(indent=4) | pp = pprint.PrettyPrinter(indent=4) | ||
c = httplib.HTTPConnection(' | c = httplib.HTTPConnection('XXX:8080') | ||
userAndPass = b64encode(b" | username = "s-scalarcloudmgt" | ||
password = "Sc@lar2016!" | |||
userAndPass = b64encode(b"s-scalarcloudmgt:Sc@lar2016!").decode("ascii") | |||
print userAndPass | print userAndPass | ||
headers = { 'Authorization' : 'Basic %s' % userAndPass } | |||
pp.pprint(headers) | |||
#then connect | #then connect | ||
c.request('GET', '/', headers=headers) | |||
c.request('GET', '/') | # c.request('GET', '/') | ||
#get the response back | #get the response back | ||
Line 38: | Line 41: | ||
# this gets the page text | # this gets the page text | ||
data = res.read() | data = res.read() | ||
</pre> | </pre> |
Revision as of 18:04, 29 May 2017
#!/usr/bin/env python from base64 import b64encode import httplib import pprint pp = pprint.PrettyPrinter(indent=4) c = httplib.HTTPConnection('XXX:8080') username = "s-scalarcloudmgt" password = "Sc@lar2016!" userAndPass = b64encode(b"s-scalarcloudmgt:Sc@lar2016!").decode("ascii") print userAndPass headers = { 'Authorization' : 'Basic %s' % userAndPass } pp.pprint(headers) #then connect c.request('GET', '/', headers=headers) # c.request('GET', '/') #get the response back res = c.getresponse() print "read()" pp.pprint(res.read()) print "" print "headers" pp.pprint(res.getheaders()) print "" print "status" pp.pprint(res.status) print "" print "reason" pp.pprint(res.reason) pp.pprint(res) # at this point you could check the status etc # this gets the page text data = res.read()