https://kotlinlang.org logo
#ktor
Title
# ktor
s

Santosh Astagi

10/22/2019, 8:41 PM
but I get this as a list, so don't want to build it here, but pass in a list
e

Evan R.

10/22/2019, 8:46 PM
https://ktor.io/servers/calls/requests.html#get use
call.request.queryParameters.getAll("sort")
Assuming you mean receiving query parameters on the server
s

Santosh Astagi

10/22/2019, 8:47 PM
yes, so if my request is like this:
Copy code
httpClient.get<String> {
  url(requestUrl)
  parameter("sort", sortOptions)
}
How do I pass it to the HttpClient
I am trying to make requests to the server
not handling on server
Using this:
e

Evan R.

10/22/2019, 8:51 PM
Does your above code not work, assuming
sortOptions
is a list?
s

Santosh Astagi

10/22/2019, 8:52 PM
no
Copy code
Sets a single URL query parameter of [key] with a specific [value] if the value is not null. Can not be used to set form parameters in the body.
That is the definition for
Copy code
parameter
e

Evan R.

10/22/2019, 8:55 PM
Got it. Just checked the API docs a little, try this:
Copy code
httpClient.get<String> {
  url {
    takeFrom(requestUrl)
    parameters.appendAll("sort", sortOptions)
  }
}
s

Santosh Astagi

10/22/2019, 8:56 PM
ok, giving it shot
FWIW, I saw this too:
e

Evan R.

10/22/2019, 8:59 PM
Unless you know something I don’t, I’m pretty sure Locations are used for receiving requests on the server side and aren’t used for the HTTP client
s

Santosh Astagi

10/22/2019, 9:00 PM
oh you are right, that is a server side thing
Can you point me to the documentation
s

Santosh Astagi

10/22/2019, 9:04 PM
my takeFrom is expecting an HttpRequestBuilder
not url
e

Evan R.

10/22/2019, 9:06 PM
You need to make sure your takeFrom is inside the URL block so it uses
URLBuilder.takeFrom
rather than
HttpRequestBuilder.takeFrom
If that doesn’t work try
this@url.takeFrom
s

Santosh Astagi

10/22/2019, 9:09 PM
It worked
Thanks a ton
👍 1
You were right again, I was using the wrong takeFrom
8 Views