Hello,

Ahmet YILDIRIM wrote:
> Hi,
> 
> I want to query information using sparql endpoint in a php script.
> I could only use get method to submit my query. I want to use larger
> queries to submit using post method. I tried something with curl
> extension but always got invalid request error.
> 
> Anyone did this before? Can you help me?
> 
> here what i tried before:
> 
> 
> $ch = curl_init("http://dbpedia.org/sparql";);
> curl_setopt($ch, CURLOPT_POST      ,1);
> curl_setopt($ch, CURLOPT_POSTFIELDS
> ,'default-graph-uri=http%3A%2F%2Fdbpedia.org&should-sponge=&query='.urlencode($sparql_query).'&format=text%2Fxmll&debug=on');
> $sonuc = curl_exec($ch);

Assuming $url is the URL you want (you can test it on the command line,
include the default graph http://dbpedia.org), you could do the following:

$headers = array("Content-Type: ".$this->contentType);
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
$contents = curl_exec($c);
curl_close($c);

$contentType can be "application/sparql-results+xml",
"application/sparql-results+json", "text/rdf+n3" etc. depending on what
you need. The result of your query is in $contents.

Kind regards,

Jens


-- 
Dipl. Inf. Jens Lehmann
Department of Computer Science, University of Leipzig
Homepage: http://www.jens-lehmann.org
GPG Key: http://jens-lehmann.org/jens_lehmann.asc


------------------------------------------------------------------------------
_______________________________________________
Dbpedia-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dbpedia-discussion

Reply via email to