Advertisement
Guest User

Untitled

a guest
Mar 28th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. Here is the wget command :
  2. wget --auth-no-challenge --http-user=auth_user --http-password=auth_pass --save-cookies cookies.txt --keep-session-cookies --post-data 'user_login=username&pass=password' https://www.helloworld.com/login.php
  3.  
  4. Here is the groovy script:
  5.  
  6. static List<String> login(String baseUrl, String path, query, method = Method.POST) {
  7. try {
  8. def ret = null
  9. def http = new HTTPBuilder(baseUrl)
  10.  
  11. http.request(method, ContentType.URLENC) {
  12. uri.path = path
  13. uri.query = query
  14.  
  15. headers.'Authorization' = "Basic ${"auth_user:auth_pass".bytes.encodeBase64().toString()}"
  16.  
  17. // response handler for a success response code
  18. response.success = { resp, data ->
  19.  
  20. println "response status: ${resp.statusLine}"
  21.  
  22. resp.getHeaders('Set-Cookie').each {
  23.  
  24. def cookie = it.value.split(";").toString()
  25. println cookie
  26. .add(cookie)
  27. }
  28. println 'Response : ' + resp.getData()
  29. }
  30. }
  31. return cookies
  32.  
  33. } catch (groovyx.net.http.HttpResponseException ex) {
  34. ex.printStackTrace()
  35.  
  36. } catch (java.net.ConnectException ex) {
  37. ex.printStackTrace()
  38.  
  39. }
  40. }
  41.  
  42. def url = "https://www.helloworld.com/login.php"
  43. def path = ""
  44. def query = [ user_login: "username@calypso", pass: "password" ]
  45.  
  46. // Submit a request via POST
  47. def response = login(url, path, query)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement