私は私のJava HttpServerをして、いくつかのSQLクエリを作成したいが、HttpServerを、私は私のブラウザに送信するリンクに特殊文字を認識していないようです:HttpServerでJavaの特殊文字が認識されるようにするにはどうすればよいですか?
:[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();
}
}
}
どのように私はこの問題を解決することができますか?
スペースやその他の記号が含まれている可能性がありますので、あなたのリンクをurlencodeする必要があります。 http://en.wikipedia.org/wiki/Percent-encoding – clamp