Set Authorization header to post request
See original GitHub issue- Request:
request(app)
.post('/api/categories')
.send(category)
.set({ Authorization: token })
.end((err, res) => {
const newCategory = res.body;
expect(res.status).to.be.equal(200);
expect(newCategory).to.be.equal(category);
done();
});
Error:
Error: "value" required in setHeader("Authorization", value)
- Request:
request(app)
.post('/api/categories')
.send(category)
.setHeader('Authorization', token)
.end((err, res) => {
const newCategory = res.body;
expect(res.status).to.be.equal(200);
expect(newCategory).to.be.equal(category);
done();
});
Error:
TypeError: (0 , _supertest2.default)(...).post(...).send(...).setHeader is not a function
How set header to post request ?
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (1 by maintainers)
Top Results From Across the Web
Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >http post - how to send Authorization header? - Stack Overflow
Unfornately there is no Authorization header. How should I add it correctly? Whole request sent by my code looks as follow: OPTIONS /oauth/token ......
Read more >POST JSON With Bearer Token Authorization Header - ReqBin
To post JSON with a Bearer Token Authorization header, you need to make an HTTP POST request, provide your Bearer Token with an ......
Read more >Authorizing requests - Postman Learning Center
You can pass auth details along with any request you send in Postman. Auth data can be included in the header, body, or...
Read more >Set the Authorization Header with Axios - Mastering JS
Setting the authorization header is a little different with post() , because the 2nd parameter to post() is the request body. You should...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note that you have to call
.set()
AFTER calling.post()
, not before. For example:You do want to use the
.set
function. You should be able to pass a single JSON object or two parameters for the key and value.In your first example I would say that there is a problem with the variable
token
.