requestify icon indicating copy to clipboard operation
requestify copied to clipboard

Sending body and headers in a request

Open serkolch opened this issue 8 years ago • 1 comments

Hey,

So I ran into this problem earlier: if you use a function other than .request(), you are not able to successfully send a request that contains headers and a body.

E.g. the below will not send a successful request

requestify.post(URL, {
    body: {data: AA},
    headers: {token: BBBB}
})

In order to send a successful request with both body and headers (and likely other attributes you may want), you need to send:

requestify.request(URL, {
    method: 'POST',
    body: {data: AA},
    headers: {token: BBBB}
})

Posting this here in case there is already a solution on the way or someone else runs into the same issue.

serkolch avatar Feb 22 '17 17:02 serkolch

Hello, you can use the example below:

requestify.post('http://your_url', { id: 1, name: 'Test', message: 'This is my payload!!' }, {
    headers: {
        token: BBBB
    }
});

hiagodotme avatar Mar 05 '19 20:03 hiagodotme