https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html阅读文档,我们看到我们能够向Fuseki端点发送一个包含汇编程序.ttl定义的POST请求。尽管在尝试时,我的应用程序没有从服务器得到任何响应。
我正在尝试用Java编写以下代码:
/**
* This Method creates a persistent TDB2 in Fuseki Server by a POST request
* @param name Name of the DataSet to be Created
* @throws MalformedURLException
* @throws ProtocolException
* @throws UnsupportedEncodingException
*/
public void createDatasetInFuseki(String name) throws Exception{
try {
HttpURLConnection conn = (HttpURLConnection) new URL(server_location + "/$/datasets").openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
File assembler_file = new File("C:\\Users\\Carlos\\Desktop\\fuseki-assembler.ttl");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
try {
InputStream fis = new FileInputStream(assembler_file);
int content;
//Read .ttl content by InputStream
while ((content = fis.read()) != -1) {
writer.write((char) content); //Write the readed content in http OutPutStream
}
} catch (IOException e) {
e.printStackTrace();
}
writer.flush();
writer.close();
os.close();
String fuseki_response = conn.getResponseMessage();
conn.connect();
}finally {}
}如果可能的话,我想知道如何通过Java客户端将文件正确地发布到服务器。
发布于 2020-02-12 21:17:29
我的错误是在文章格式上。我用这个问题Upload files from Java client to a HTTP server解决了我的问题
通过发布Assembler.ttl,我们可以使用Reasoner编程实例化Fuseki数据集。这使得服务器能够在执行时对包含的数据进行推理。
https://stackoverflow.com/questions/60171943
复制相似问题