updating myDB via POST not working...

14 views
Skip to first unread message

Borja Ramis

unread,
Dec 2, 2014, 11:24:57 AM12/2/14
to sta...@clarkparsia.com
Hi,

I am trying to update my DB via POST and I cannot success... I am using ajax in smal html+js implementation. The code of the request that could be useful for someone to help me is attached after my problem definition.
I have a SPARQL Update query for inserting data to a DB that is hosted in my Stardog server. the query works perfectly in Stardog interface but not doing it via POST. Following the "SPARQL 1.1 Protocol 2.2.2 update via POST directly" I am including the SPARQL update request string, unencoded, and nothing else as the message body of the request. (the query string is "data" variable). In addition, I am settting the content type header of the HTTP request to application/sparql-update. Besides what it is found in the request that is attached, I have trying encoding the query and using other content type and it does not work either.

The error that I have now is  [HTTP/1.1 406 application/sparql-update is not an supported accept type 1ms]. If I change to encoded query I am getting  [HTTP/1.1 415 application/x-www-form-urlencoded; charset=utf-8 is not a supported input type for /{db} 2ms]

What am I doing wrong in the request? Thanks in advance!

var data = updateQuery;
                var urlUpdate = "http://localhost:5820/myDB/update";
                $.ajax({
                    url: urlUpdate,
                    type: "POST",
                    data: data,
                    headers: {
                        "Accept": "application/sparql-update"
                    },
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader('Authorization', make_base_auth("admin", "admin"));
                    }
                });

Borja Ramis

unread,
Dec 2, 2014, 6:55:43 PM12/2/14
to sta...@clarkparsia.com
Hi, me again... I solve it so I would like to share the solution to my "mistake" just in case anyone has this problem.

I have changed the header, replacing "Accept" by "Content-Type". Now it works fine. Here you are the correct ajax POST (it should be noted that the "updateQuery" variable contains the SPARQL Update query):


var data = updateQuery;
                var urlUpdate = "http://localhost:5820/myDB/update";
                $.ajax({
                    url: urlUpdate,
                    type: "POST",
                    data: data,
                    headers: {
                        "Content-Type": "application/sparql-update"

                    },
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader('
Authorization', make_base_auth("admin", "admin"));
                    }
                });

Reply all
Reply to author
Forward
0 new messages