var http = require('http')
function getSPARQLResults(query_string, callback) {
sparqlQ = getSPARQLPrefix() + query_string;
var options = {
host: 'localhost',
port: 8080,
path: '/openrdf-sesame/repositories/myRepo?query=' +encodeURIComponent(sparqlQ) + '&content-type=application/sparql-results+json',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/sparql-results+json',
},
};
//console.log ( encodeURIComponent(query_string) );
console.log ( query_string );
var req = http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
console.log (data);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
req.end();
}
响应(当 node.js 服务器在 Amazon EC2 Linux 实例上运行时)
Got response: 400
HEADERS: {"date":"Wed, 24 Apr 2013 04:12:12 GMT","content-language":"en-US","content-type":"text/plain; charset=utf-8","content-length":"86","server":"Jetty(6.1.26)"}
undefined:1
MALFORMED QUERY: Lexical error at line 1, column 7. Encountered: "%" (37), af
^
响应(当 node.js 服务器在 Ubuntu 笔记本电脑上运行时)
Got response: 200
HEADERS: {"date":"Wed, 24 Apr 2013 04:20:37 GMT","vary":"Accept","content-language":"en-US","content-type":"application/sparql-results+json; charset=UTF-8","content-disposition":"attachment; filename=query-result.srj","transfer-encoding":"chunked","server":"Jetty(6.1.26)"}
两个标头之间的 Content-Type 不同。缺少什么/出了什么问题??