Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is the wget command :
- 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
- Here is the groovy script:
- static List<String> login(String baseUrl, String path, query, method = Method.POST) {
- try {
- def ret = null
- def http = new HTTPBuilder(baseUrl)
- http.request(method, ContentType.URLENC) {
- uri.path = path
- uri.query = query
- headers.'Authorization' = "Basic ${"auth_user:auth_pass".bytes.encodeBase64().toString()}"
- // response handler for a success response code
- response.success = { resp, data ->
- println "response status: ${resp.statusLine}"
- resp.getHeaders('Set-Cookie').each {
- def cookie = it.value.split(";").toString()
- println cookie
- .add(cookie)
- }
- println 'Response : ' + resp.getData()
- }
- }
- return cookies
- } catch (groovyx.net.http.HttpResponseException ex) {
- ex.printStackTrace()
- } catch (java.net.ConnectException ex) {
- ex.printStackTrace()
- }
- }
- def url = "https://www.helloworld.com/login.php"
- def path = ""
- def query = [ user_login: "username@calypso", pass: "password" ]
- // Submit a request via POST
- def response = login(url, path, query)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement