Coder Social home page Coder Social logo

Comments (5)

sholladay avatar sholladay commented on June 1, 2024

Your code looks fine to me.

We can narrow down the problem a little bit if you try each of these and tell me what happens:

  1. Without .json()
const response = await ky.post( 'http://127.0.0.1:8055/auth/login', {
                json: {
                    email: body.email,
                    password: body.password
                },
            } )
  1. Using body instead of json option
const response = await ky.post( 'http://127.0.0.1:8055/auth/login', {
                body: JSON.stringify({
                    email: body.email,
                    password: body.password
                }),
            } ).json()
  1. Using body instead of json option and without .json()
const response = await ky.post( 'http://127.0.0.1:8055/auth/login', {
                body: JSON.stringify({
                    email: body.email,
                    password: body.password
                }),
            } )

I don't know if Director requires a Content-Type: application/json header or if it just assumes it, but you might need to add that header to snippets 2 & 3 above since the body option is being used.

from ky.

sindresorhus avatar sindresorhus commented on June 1, 2024

Can you try out https://github.com/sindresorhus/ky/releases/tag/v1.1.1 ?

from ky.

i-geobot avatar i-geobot commented on June 1, 2024

Pardon for the belated reply.

The issue was related to node version that handled headers incorrectly. Upgrading node fixed it.

Many thanks for support and time!

from ky.

phoenisx avatar phoenisx commented on June 1, 2024

I feel this issue resembles mine as well.

I am using this library on NodeJS v20.9, and found out that sending a .post() request using this library didn't work. The headers was always set to text/plan.
I tried forcefully setting the content-type header to application/json, but it didn't change. Not sure why even after setting the headers it's getting passed as text/plain 🤔

To give more context, my setup includes Sveltekit and a Fastify Backend, both running on NodeJS v20.9.
The issue doesn't happen when I replace it with axios. but I can replicate it with NodeJs's native fetch function as well.

from ky.

havgry avatar havgry commented on June 1, 2024

Have you tried setting content-length manually? See #514

from ky.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.