Skip to main content

Extracting http parameters using HttpExchange

4 replies [Last post]
byhisdeeds
Offline
Joined: 2006-01-06
Points: 0

First let me say that I appreciate the inclusion of a base HttpServer in the core java api as it allows me to implement a number of facilities such as debug querying, and lightweight client server interations in my application without much effort.

That said, does anybody know if there are any utilities such as getParameter and other such code in the base API. I can't find any info on it and I'm about to implement my own.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
byhisdeeds
Offline
Joined: 2006-01-06
Points: 0

I tried this.

BufferedInputStream bis = new BufferedInputStream(exchange.getRequestBody());
byte b[] = new byte[256];
int bRead;
while ((bRead = bis.read(b)) != -1)
{
for (int i=0; i System.out.print("["+String.valueOf((int)b[i])+"]");
System.out.println();
}
bis.close();

But no data is read from the inputstream. Am I doing something wrong.

gmanwani
Offline
Joined: 2004-07-12
Points: 0

Please use HttpExchange.getRequestBody() to get the parameters you are looking for.

mbilgin
Offline
Joined: 2006-05-18
Points: 0
byhisdeeds
Offline
Joined: 2006-01-06
Points: 0

The exchange.getRequestHeaders() does not unpack the url ?...&....&... parameters which is what I want. Are there any utilities in the package to do this.