K
K
kolesov_vladislav2021-02-06 17:04:10
HTML
kolesov_vladislav, 2021-02-06 17:04:10

How to send a variable and its value (node ​​js) post request to the server?

I can't figure out how to send the variable name and value to the server
Here is my code:

const data = JSON.stringify(
        receiver = 4100116212277840
    )
req.write(data)


I understand perfectly well that I am passing the receiver variable and at the same moment I am assigning a value to it and it turns out that I am only passing the value itself.
This is what the server finally receives:
statusCode: 201
{
"4100116212277840": "",
"id": 11
}
But I need such a request to the server:
{
"receiver ": "4100116212277840",
"id": 11
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
Xoggas, 2021-02-06
@Xoggas

Try like this

const data = JSON.stringify({
    receiver: 4100116212277840
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question