Re : Getting Header Information.

43 views
Skip to first unread message

Sri Vidhya

unread,
May 14, 2013, 8:08:48 AM5/14/13
to nod...@googlegroups.com
HI am sending the header information (like below)to node.js on the server side, but it is not working.
How to pass the header information to server from client. and how to get on the server side .
Pls if anyone knows... let me know
 
this is the ajax request call fron client html page:

client.html:
 
          $.ajax({
                    //  url:'http://10.163.14.52:8888/all',
                    url:'http://IPaddress:port/getTaluk/',
                    type:'POST',
                    datatype:'json',
                    data:inputVal,
                    headers : {
                                'emp_value':s,
                                'signature':hash,
                                'timestamp':t
                                },
                    complete:function(){
                        alert(":"+data);
                     
                      
                    }
                 });

on the server side am getting like this using nodejs:

  console.log("emp_value:"+req.headers['emp_value']);
but i can't able to get it.

--
Thanks,
N. Srividhya.

Charles Care

unread,
May 14, 2013, 8:34:23 AM5/14/13
to nod...@googlegroups.com
Hi Sri,

You'll probably need to share a bit more server-side code than just the console.log() so that we can see what you're trying to do.

Thanks,

Charles

Sri Vidhya

unread,
May 15, 2013, 8:11:46 AM5/15/13
to nod...@googlegroups.com
Hi All,
     This is srividhya working on nodeJS. I have one query regarding getting the header information from the ajax request(on client side html page) to the server side code on NodeJS. Here in the below code on headers section am having "emp_value" as "XYZ", so i want to get  the "XYZ" on server side through NodeJS. With this i will send the ajax request on html page and the server side code which i have used to get the header information. But it is not giving the header information, also if am using the header:{} on ajax request with post method , it wont call the nodeJS serverside code. Anyone tell how to get the header value which is coming from the header request.



client.html: 
       $.ajax({
                    //  url:'http://10.163.14.52:8888/all',
                    url:'http://IPaddress:port/getTaluk/',
                    type:'POST',
                    datatype:'json',
                    data:inputVal,
                    headers : {
                                'emp_value':'XYZ',

                                'signature':hash,
                                'timestamp':t
                                },
                    complete:function(){
                        alert(":"+data);
                      
                       
                    }
                 });

server side:

var express = require('express')
var app = express.createServer();
app.use(express.bodyParser());
app.get('/getTaluk', function(request, response){
console.log("eneters :::"); 
console.log("emp_value:"+request.headers['custom_header']);  //code used to get header information
app.listen(8889);
});
console.log("Server has started.");



--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks,
N. Srividhya.

Charles Care

unread,
May 15, 2013, 8:39:40 AM5/15/13
to nod...@googlegroups.com
Hi Srividhya,

Two things I noticed:

1) you're call to app.listen() needs to be outside your app.get
method. Based on the snippet above, it'll only bind to port 8889 once
a request is received (so will never happen).

2) you need to replace 'custom_header' with 'emp_value' if that's the
specific header you want.

When I made these changes (see https://gist.github.com/ccare/5583700)
it started working.

Hope that helps,

Charles

Sri Vidhya

unread,
May 15, 2013, 8:59:56 AM5/15/13
to nod...@googlegroups.com
Hai thanks for the reply....

i changed the code like this even it is not working ..and one more thing here am using get method.

var https = require('http');
var pg = require('pg');

var express = require('express')
var app = express.createServer();

app.use(express.bodyParser());

app.get('/getTaluk', function(request, response){
console.log("eneters :::");

console.log("emp_value:"+request.headers['emp_value']); 

});

app.listen(8889);

console.log("Server has started.");

mscdex

unread,
May 15, 2013, 9:30:59 AM5/15/13
to nodejs
On May 15, 8:59 am, Sri Vidhya <sr.vidh...@gmail.com> wrote:
> app.get('/getTaluk', function(request, response){

This needs to be app.post
Reply all
Reply to author
Forward
0 new messages