4

I'm trying to authenticate automatically using Paw and to do this I need to

  1. make a request to the login page
  2. parse the html response to get an auth token from a login form
  3. send the authentication request

but I don't know how to do that...

Anyone has an idea?

Thanks

titiyoyo
  • 911
  • 1
  • 11
  • 28

1 Answers1

3

In paw first set up the request to the login page. Then in a second request you can asses the response body of the first request: we can use a regex filter on the raw response of another request.

create a custom dynamic value: Adding a custom dynamic value

then use the code below to set the custom dynamic value.

function evaluate(context){
 // Set up your regex to extract the token
 var re = /<h2>([^<]+)<\/h2>/;
 
 // Replace the 'Login page' with your request name 
 var request = context.getRequestByName('Login page')
 var lastExchange = request.getLastExchange()
 var body =  lastExchange.responseBody
 
 var m = re.exec(body)
 return m[1]
};
Matthaus Woolard
  • 2,310
  • 11
  • 13