Skip to content

Instantly share code, notes, and snippets.

@robotarmy

robotarmy/--- out

Created Jun 1, 2010
Embed
What would you like to do?
"POST"
{"href":"/","pathname":"/"}
{"host":"ledger.robotarmyma.de:7001","user-agent":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3","accept":"text/javascript, application/javascript, */*","accept-language":"en-us,en;q=0.5","accept-encoding":"gzip,deflate","accept-charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.7","keep-alive":"115","connection":"keep-alive","content-type":"application/x-www-form-urlencoded; charset=UTF-8","referer":"http://ledger.robotarmyma.de:3000/public/test/index.html","content-length":"91","origin":"http://ledger.robotarmyma.de:3000","pragma":"no-cache","cache-control":"no-cache"}
";jsonp1275368382519({\"pony\":\"cake\",\"name\":\"biscuit\"});"
Response Headersview source
Content-Length 54
Content-Type application/json;charset=uft-8
Connection like a leaf on the wind
Request Headersview source
Host ledger.robotarmyma.de:7001
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept text/javascript, application/javascript, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Referer http://ledger.robotarmyma.de:3000/public/test/index.html
Content-Length 91
Origin http://ledger.robotarmyma.de:3000
Parametersapplication/x-www-form-urlencoded
JSON {"pony":"cake","name":"biscuit"}
callback jsonp1275368382519
Source
JSON=%7B%22pony%22%3A%22cake%22%2C%22name%22%3A%22biscuit%22%7D&callback=jsonp1275368382519
module("LedgerService");
$.ajaxSetup({
url: 'http://ledger.robotarmyma.de:7001',
});
var item = {pony :'cake', name : 'biscuit'};
asyncTest("POST one with jsonp", 2, function(){
$.ajax({
type:'POST',
data: {JSON:JSON.stringify(item) },
dataType:'jsonp',
success: function(data,status,xhr) {
ok(status =='success', "status -" +status);
ok(true,"Cross Domain Access-Control-Allow-Origin");
ok(data != null,"Post Returned Something");
},
error:function() {
ok(true);
ok(false,"error - on post");
},
complete:function(xhr,status) {
start();
}
});
});
LedgerService.prototype.POST = function(request,response,data) {
var uri = url.parse(request.url,true)
RH(request)
out = ";"+data['callback']+"("+data['JSON']+");";
PJ(out);
response.writeHead(200, 'from one post to another - walking the way',{
'Content-Length': out.length,
'Content-Type': 'application/json;charset=uft-8',
'Connection' : 'like a leaf on the wind'
});
response.write(out,'utf8');
response.end();
}
LedgerService.prototype.service = function() {
var self = this;
var http = require('http'),
sys = require('sys');
self.server = http.createServer();
self.server.addListener('request',function(request,response) {
var data = "";
var method = request.method;
PJ(method);
request.setEncoding('UTF8');
request.addListener('data',function(chunk) {
data += chunk;
});
request.addListener('end',function() {
var json = querystring.parse(data);
self[method](request,response,json);
});
});
self.server.addListener('close',function(errno) {
sys.puts('close ' + errno);
});
self.server.listen(7001);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment