Hi All,
I am trying sending some Custom Headers from Client to Server. The
following ajax call is capable to send header information to server.
*Client AJAX Call:*
$.ajax({
type: "GET",
url: "ws_url",
dataType: "jsonp",
headers:{
"custom_header":"head_val"
},
success: function(data) {
alert(data)
}
});
With above ajax call, I can get the header information at server end using
JAVA based Apache CXF Web Services like below:
String client_custom_header =
HttpHeaders.getRequestHeaders().getFirst("custome_header");
//I am getting the header value "head_val".
If I am trying to implement same thing in node.js with express frame work;
I cannot read the headers info.
*
Please find my node.js code:*
var https = require('http');
var express = require('express')
var app = express.createServer();
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type,
Authorization, Content-Length, X-Requested-With');
};
app.configure(function () {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
// app.use(allowCrossDomain);
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.get('/getData', function(request, response){
console.log('STATUS: ' +
response.getHeader('custom_header'));//undefined
console.log('HEADERS: ' + JSON.stringify(response.headers));//undefined
console.log("emp_value:"+request.headers['custom_header']); //undefined
console.log("\n\n*****111*******"+request.body); //undefined
console.log('params: ' + JSON.stringify(request.params));//[]
console.log('header: ' +
JSON.stringify(request.header("Access-Control-Allow-Origin", "*")));//"*"
console.log('body: ' + JSON.stringify(request.body));//undefined
console.log('query: ' + JSON.stringify(request.query));//{"d":"20"}
console.log('query: ' + request.query.d);//20
});
app.listen(8889);
---------------------------------------------------------
I tried several options but I couldn't. Please help me soon.........
Thanks in advance..
Ramesh
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.