我正在与Jena合作阅读rdf文件。但我的代码有时会在线返回403 Forbidden:
model.read(string, "");
如果来自该行的响应代码不是200,如何处理?我已经尝试过这种方式,但它没有用(因为model.read(string,“”);不是字符串)
URL url = new URL(model.read(string, ""));
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
我的代码:
Model modelTmp = ModelFactory.createDefaultModel();
modelTmp.read(string, "");
String queryString =
"PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> " +
"select distinct ?rdr " +
"WHERE {?s dbpedia-owl:wikiPageRedirects ?rdr }";
Query query = QueryFactory.create(queryString);
try (QueryExecution qexec = QueryExecutionFactory.create(query, modelTmp)) {
ResultSet results = qexec.execSelect() ;}