0

I am using the NPM Request library to make an API call in which I want to pass Header as well as form. Until the time I wanted only formdata the API call was working fine but as soon as added the header in the API call it is showing the following error:-

" Failed to construct 'Headers': Please use the 'new' operator.... "

Here Is My API call:-

send:function(endpoint,callback, token, formdata, component){
                this._request.post(endpoint, Headers : { Authorization :token 
                      }, {form: formdata},function (error, response, body) {
                    if (!error && response.statusCode == 200) {
                        callback(response.body, component);
                    }else if(!error && response.statusCode == 400){

                    }
                })
            },

1 Answer 1

1

Change your code with this :

You can pass the headers as simple as json object but the format should be like this :

this._request.post(endpoint, { headers : { Authorization : token } , form: formdata },

    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            callback(response.body, component);
        }else if(!error && response.statusCode == 400){

        }
    })

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

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.