【发布时间】:2017-04-03 14:47:41
【问题描述】:
我在我的节点应用程序中使用“请求”模块在位于 fuseki 服务器中的本体模型中发布数据。我正在使用以下代码:
var request = require('request');
var querystring = require('querystring');
var myquery = querystring.stringify({update: "PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#> INSERT { ?KPIs test:hasValue 2009} WHERE { ?KPIs test:hasValue ?Newvalue}"});
request.post('http://localhost:3030/DS-1/sparql?'+myquery, function (error, response, body) {
if (!error && response.statusCode == 200) {
// Show the HTML for the Google homepage.
console.log('successful update');
console.log(body);
} else {
console.log(response.statusCode);
console.warn(error);
}
});
PS:当我使用 POSTMAN 发送 Post 请求以插入数据时,它工作正常,但在我的节点应用程序中,它没有。它显示错误“错误请求 400”。 P.S:GET 方法在 POSTMAN 和节点应用程序中都可以正常工作。
【问题讨论】:
-
我的猜测是服务器正在寻找表单数据而不是查询参数,在 Postman 中,您如何在工作时发送 POST 请求?也可能值得在
myquery上做一个console.log,看看它是否正确形成。 -
在 Postman 中,使用 POST 方法 :: localhost:3030/DS-1/… 的查询看起来像这样。 P.s:我在节点应用程序中尝试过这种格式,但它不起作用,是的,'myquery' 格式正确,我已经检查过了,我也尝试过像上面那样直接放置 url。
标签: node.js sparql ontology fuseki http-method