Login and query paths are different, how do I setup WSClient?

This is not doing the job:

val wsRequest = ws.url(loginURL).withAuth(userName, password, WSAuthScheme.BASIC).execute()

val wsDataRequest = ws.url(queryURL).withAuth(userName, password, WSAuthScheme.BASIC).post(file)

Is there a way to combine the query and the login?

And is there a way to combine the two lines into one statement?

I don’t understand the question. What are you trying to do and what’s the error?

1 Like

Thank you, Will.

The service I am trying to pull data from provides two links, one for login and another for the query. It looks like this:

val baseURL = “https://www.websitename.org
val authenticationPath = “/ajaxauth/login”
val queryPath = “/basicdomaindata/query/class/tle/ABC/CDE”
val loginURL = baseURL+authenticationPath
val queryURL = baseURL+queryPath

So how best can I both authenticate and query the system? Do I issue two separate commands, one for login and another to query:

val wsRequest = ws.url(loginURL).withAuth(userName, password, WSAuthScheme.BASIC).execute()
val wsDataRequest = ws.url(queryURL).post(file)

Or is there a way to do both with one statement?

I appreciate your response and apologies if my questions are naive. I love coding in Scala but this is the first time working with reactive Lightbend framework.

Much appreciated!

On the second command in the setup above, I am getting the following statements in response:

16:39:01.273 [info] play.shaded.ahc.org.asynchttpclient.netty.handler.intercept.Unauthorized401Interceptor [] - Can’t handle 401 as auth was already performed
{“error”:“You must be logged in to complete this action”}