1
votes

I am trying to send a Post request with axios to a WebApi on my server, testing the API with PostMan the API accepts and works fine.

But on my React Native App, when I send the axios.post it returns "Error: Request failed with status code 415". When I send the post with the postData it Returns Error:Network Error, and when I send the way bellow it returns Error 415.

I made a lot of searches but could not solve this. Can someone give a hand on this? Bellow is my js code.

let postData = new FormData();
                          postData.append('file',{ uri: response.uri });
                          postData.append('auditid',auditID);
                          //axios.post("http://172.16.0.10:8081/api/auditpicture/", postData,{

                          axios.post("http://172.16.0.10:8081/api/auditpicture/",{
                            headers: {
                              "Content-Type": 'multipart/form-data; boundary=${formData._boundary}',
                             }
                              ,
                              body:
                               [{
                                 file:response.uri,
                                 auditid:auditID
                               }]
                          }).then(response=> {
                            console.log(response.data)
                          }).catch(error=>{
                            console.log(error);

                          })

Here is the return from PostMan: enter image description here

1

1 Answers

0
votes

after a long time I will post an answer to this question. I gave up on using axios to post the image, after find out that others had the same issue, instead I've used RNFetchBlob.fetch lib, which worked pretty easily.