【发布时间】:2023-03-19 16:40:02
【问题描述】:
https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html 阅读文档,我们看到我们能够向 Fuseki Endpoint 发送包含汇编器 .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 客户端正确地将文件 POST 到服务器。
【问题讨论】: