我想用我的 Java HttpServer 进行一些 SQL 查询,但似乎 HttpServer 无法识别我提交到浏览器的链接中的特殊字符:
[1]: http://localhost:8001/test?query=SELECT * WHERE{ ?s rdf:type ?o. }
我总是收到这样的回复:
400 Bad Request
URISyntaxException thrown
这是我的服务器的代码:
public class SimpleHttpServer
{
public static void main(String[] args) throws Exception
{
dir = args[0];
HttpServer server = HttpServer.create(new InetSocketAddress(8001), 0);
server.createContext("/test", new MyHandler());
server.setExecutor(null);
server.start();
}
static class MyHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
String response ;
System.out.println(t.getRequestURI().getQuery().toString().replaceAll("query=", ""));
response = ExecuteHttpQuery.getInstance().httpQuery(t.getRequestURI().getQuery().toString().replaceAll("query=", "").toString(), dir) + "\n";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
}
我怎样才能解决这个问题?