Using Ktor http client to make a request to my Nod...
# ktor
n
Using Ktor http client to make a request to my Nodejs backend. Tried sending a request manually and it is working, tried with my app, the body is missing. So it has to be something with my setup
Copy code
val data = JSONObject()
        data.put("email", "email")
        data.put("name", "testname")
        data.put("companyName", "testcompname")

        return singleFromCoroutine {
            try {
                val response: HttpResponse =
                    <http://client.post|client.post>("${serverUrl}${apiEndpoint}/account") {
                        body = data.toString()
                        contentType(ContentType.Application.Json)
                    }
Not sure what is happening, I'll post the entire request that gets received by the server
https://pastecode.io/s/1gidws0i Alongside
Copy code
[Node] SyntaxError: Unexpected token " in JSON at position 0
[Node]     at JSON.parse (<anonymous>)
a
Could you please share your configuration for the client?
If you use the JsonFeature you should let the Ktor serialize the body. Here you find the explanation for a similar problem.
n
@Aleksei Tirman [JB] Seems that is the case, so basically I just drop the
data.toString
and leave it as a JSONObject?
a
Yes.