Reputation: 21329
In my web-app the client pings the server (tries to contact a ping servlet on the server) wheere the address / resource locator of the servlet is :
"192.168.43.187/server/ping?" + new ClientAddress().getNetworkIP();
Till now the client has been sending it's network IP to the server with every ping. I wanted to add another piece of information with this URL,which is new GregorianCalendar().getTimeInMillis();
.
How do I send this along ?
Note :
In the URL, ping is a servlet
Upvotes: 0
Views: 505
Reputation: 272417
I would construct the URL thus:
"192.168.43.187/server/ping?ip=" + (new ClientAddress().getNetworkIP()) + "&time=" + (new GregorianCalendar().getTimeInMillis());
and use the servlet request method ServletRequest.getParameter() to extract the values.
Note that ServletRequest.getRemoteAddr() gives you the client address. Do you need to pass it explicitly ? Additionally, constructing a URL by string concatenation works in this trivial scenario, but as soon as you pass values that include characters such as spaces etc. you'll need to encode these values.
Upvotes: 1
Reputation:
"192.168.43.187/server/ping?ip=" + new ClientAddress().getNetworkIP() +
"&time=" + new GregorianCalendar().getTimeInMillis();
You will need to change "ping" servlet in order to read those parameters.
Upvotes: 2