带有帐号密码验证的apche服务器文件下载
生活随笔
收集整理的這篇文章主要介紹了
带有帐号密码验证的apche服务器文件下载
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
?使用python訪問
#!/usr/bin/python #fileencoding:utf-8def?testUrl():import?urllib2import?sysimport?reimport?base64from?urlparse?import?urlparse#下載路徑theurl?=?'http://ip/release/LHJH/Server/er_service.war'username?=?'username'password?=?'username'??req?=?urllib2.Request(theurl)base64string?=?base64.encodestring('%s:%s'?%?(username,?password))[:-1]authheader?=??"Basic?%s"?%?base64stringreq.add_header("Authorization",?authheader)try:handle?=?urllib2.urlopen(req)except?IOError,?e:#?here?we?shouldn't?fail?if?the?username/password?is?rightprint?"It?looks?like?the?username?or?password?is?wrong."sys.exit(1)thepage?=?handle.read()print?thepageif?__name__?==?"__main__":testUrl()?
?從瀏覽器訪問的方式:
http://username:password@ip/release/LHJH/Server/er_service.war?
?
轉(zhuǎn)載于:https://my.oschina.net/yangting880815/blog/649328
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的带有帐号密码验证的apche服务器文件下载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WebService学习笔记---CXF
- 下一篇: URLEncode编码和URLDecod