IronPython : url request (thru ntlm proxy too)


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // with default cred
  2. ccred = CredentialCache.DefaultCredentials
  3.  
  4. // or special cred
  5. myCred = NetworkCredential(login,password,domaine)
  6. ccred = CredentialCache()
  7. ccred.Add(Uri(host), "NTLM", myCred)
  8.  
  9.  
  10. from System.Net import *
  11.  
  12. def download(url,file, cred=None):
  13. wc=WebClient()
  14. if cred:
  15. wc.Credentials = cred
  16. wc.DownloadFile(url,file)
  17.  
  18. def getContent(url, cred = None):
  19. wr = WebRequest.Create(url)
  20. if cred:
  21. wr.Credentials = cred
  22. rp=wr.GetResponse()
  23. r=StreamReader(rp.GetResponseStream(),Encoding.UTF8)
  24. return r.ReadToEnd()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.