I am writing an application where the user inputs song information that will then be viewed on a website. I am trying to get this HttpGet request to work. I really don’t need the server to return any information. I just need the information to store in the MySQL database. On the php side of things I use $_GET to pull the information. Am I approaching this the wrong way? Here is my android code:
public void executeHttpGet() throws Exception{
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(
"http://localhost:8888/?title=hello&artist=horray");
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Why not try using a POST instead? Take a look at this article:
http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient