4

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?

relez
  • 750
  • 2
  • 13
  • 28

2 Answers2

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.

Gaurav Roy
  • 11,175
  • 3
  • 24
  • 45
Yeonghun
  • 400
  • 5
  • 13
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());
})
Vasyl Nahuliak
  • 1,912
  • 2
  • 14
  • 32