2017-04-03 11 views
0

내 노드 응용 프로그램에서 '요청'모듈을 사용하여 fuseki 서버에있는 온톨로지 모델의 데이터를 POST합니다. 나는 다음과 같은 코드를 사용하고 있습니다 :노드 js에서 HTTP POST 요청을 통해 SPARQL을 통해 데이터 삽입

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를 : 나는 그것이 잘 작동하지만 내 노드 응용 프로그램에서 데이터를 삽입 할 POST 요청을 보낼 POSTMAN를 사용하는 경우, 그렇지 않습니다. '잘못된 요청 400'오류가 표시됩니다. P .: GET 메서드는 POSTMAN과 노드 응용 프로그램에서 잘 작동합니다.

+0

내 생각 엔 서버가 우편 매개 변수가 아닌 폼 데이터를 찾고 있습니다. 작동 할 때 POST 요청을 어떻게 보내나요? 'myquery'에 대해'console.log'를 수행해 볼 가치가있을 수도 있습니다. – BenShelton

+0

포스트맨에서 POST 메서드로 다음과 같은 쿼리가 나타납니다. http : // localhost : 3030/DS-1 /? update = PREFIX + 테스트 % 3A % 3Chttp % 3A % 2F % 2Fwww.semanticweb.org % 2Fmuhammad % 2Fontologies % 2F2017 % 2F2 % 2Fontitled-ontology-14 % 23 % 3E % 0D % 0AINSERT + % 7B + % 3FKPIs + 테스트 % 3AhasValue + 11 % 7D % 0D % 0AWHERE % 0D % 0A ++ % 7B + % 3FKPI + 테스트 % 3AhasValue + % 3FNewvalue % 7D . P.s : 노드 응용 프로그램에서이 형식을 시도했지만 제대로 작동하지 않았습니다. 예 'myquery'가 올바르게 구성되어 있으며이를 확인한 후 위의 URL과 같은 URL을 직접 입력 해 보았습니다. –

답변

0

문제가 해결되었습니다. 게시 요청의 형식이 잘못되었습니다. 수정 된 형식은 다음과 같습니다.

var request = require('request'); 
 
var querystring = require('querystring'); 
 

 
var myquery2 = querystring.stringify({update: "PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#> INSERT { ?KPI_Variables test:hasValue_ROB1 2000} WHERE { ?KPI_Variables test:hasValue_ROB1 ?Newvalue FILTER(?KPI_Variables= test:Actual_Production_Time)}"}); 
 

 
request.post({headers: {'content-type' : 'application/x-www-form-urlencoded'},url:'http://localhost:3030/DS-1/?'+myquery2 }, 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); 
 
    } 
 
});

은 내가 '헤더'내 request.post에서 'URL'요소가 누락되었습니다.

0

/DS-1/sparql은 쿼리 서비스입니다.

INSERT은 업데이트 작업입니다.

콘텐츠 유형과 요청의 본문에 업데이트를 POST하는 것이 좋습니다 /DS-1/update

보십시오. ?update=이 작동하지 않을 수 있습니다.

+0

나는 그걸 시도했지만 다음과 같은 오류도 준다 : [2017-04-04 11:59:50] Fuseki INFO [48] 404 Not found : dataset = 'DS-1'service = 'update = PREFIX % 20test % 3A % 3Chttp % 3A % 2F % 2Fwww.semanticweb.org % 2Fmuhammad % 2Fontol ogies % 2F2017 % 2F2 % 2Funtitled-ontology-14 % 23 % 3E % 20INSERT % 20 % 7B % 20 % 3FKPI % 20Test % 3A hasValue % 202009 % 7D % 20WHERE % 20 % 7B % 20 % 3FKPI % 20Test % 3AhasValue % 20 % 3FNewvalue % 7D ' –

+0

이제 "404 찾을 수 없습니다."라는 점에 유의하십시오. 서버의 구성을 점검하여 갱신이 사용 가능한지 확인하십시오. (--update, 또는 설정 파일을 사용하는 경우 업데이트). – AndyS