A bit of background, I'm creating an SMS Gateway to have the Android phone act as a mini Web Server/SMS Gateway. Whenever a SMS is received, it posts to a web service (external). The web service (external) responds back to the Android's IP Address as a GET request with parameters.
I'm trying to get the parameters of a request made to my android application web service. The object request
seems to work OK, but I"m having issues parsing through the parameters.
The output of
Log.i("WEB_REQUEST", request.getRequestLine().toString());
is
GET /send.html?smsto=testtes&smsbody=testers HTTP/1.1
However, whenever I try to return a specific parameter, it only returns null.
HttpParams params = request.getParams();
Log.i("WEB_REQUEST", params.getParameter("smsto").toString());
Log.i("WEB_REQUEST", params.getParameter("smsbody").toString());
How can I do something like String smsto = params.getParameter("smsto").toString();
to return the value of a parameter in the GET
request?
I ended up doing this. It seems strange that the getParameter
doesn't work. I'm using the exact same variable in this solution, but storing the parameters in a list. I had hoped to not have to use a loop even though this should have minimal impact. Doesn't seem to be that agile.
List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(request.getRequestLine().getUri()), HTTP.UTF_8);
for (NameValuePair nameValuePair : parameters) {
Log.i("WEB_REQUEST", nameValuePair.getName() + ": "+ nameValuePair.getValue());
}