سؤال

I'm sending http request with request header with this code:

HttpPost httpPost = new HttpPost(url);
Http.post.addHeader("User-Agent",  "Android");

I'm trying to get this request header from Node.js by the following method:

app.post('/', function(req, res){
var ua = req.header('user-agent');
console.log(ua);
});

But It is showing me that header is unavailable. When I send this request through android browser It gives me complete request header information. How to resolve this issue?

هل كانت مفيدة؟

المحلول

Request header keys are case sensitive so you should write:

httpPost.addHeader("user-agent",  "Android");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top