I am trying to create a simple HttpServer in Java to handle GET requests, but when I try to get the GET parameters for a request I noticed the HttpExchange class does not have a
Building on the answer by @anon01, this is how to do it in Groovy:
Map getQueryParameters( HttpExchange httpExchange )
{
def query = httpExchange.getRequestURI().getQuery()
return query.split( '&' )
.collectEntries {
String[] pair = it.split( '=' )
if (pair.length > 1)
{
return [(pair[0]): pair[1]]
}
else
{
return [(pair[0]): ""]
}
}
}
And this is how to use it:
def queryParameters = getQueryParameters( httpExchange )
def parameterA = queryParameters['A']