5

I am trying to send data to a POST api but I can't figure out what's the correct syntax, I am using this:

RNFetchBlob.fetch(
    'POST',
    'htttp://www.myserver.com/api/login',
    { 'Content-Type': 'application/json'}
)
.then(response => {
    console.log(response.json());
})

Any help please?

1

2 Answers 2

2

import RNFetchBlob from "rn-fetch-blob";

RNFetchBlob.fetch(
            'POST',
            'http://www.myserver.com/api/login',
            { 'Content-Type': 'application/json'},
            JSON.stringify({key: value})
        )
        .then(response => {
            console.log(response.json());
        })

And pass the last params by JSON.stringify.

Sign up to request clarification or add additional context in comments.

1 Comment

It is better if you explain your answer a little instead of posting just a code block.
0

You forgot to upload the file itself.
Pass the fourth argument - file in base64
Library docs

RNFetchBlob.fetch(
    'POST',
    'htttp://www.myserver.com/api/login',
    { 'Content-Type': 'application/json'},
    file
)
.then(response => {
    console.log(response.json());
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.