Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Triggered when user clicks button
- public void btn_click(View v) throws IOException {
- //create and send new http request
- Request req = new Request();
- req.url = "http://localhost/wijndisplay";
- System.out.println(req.send(null));
- }
- public class Request {
- public String url;
- private HttpClient client;
- private HttpGet get;
- private HttpResponse response;
- public String send(Map<String, String> data) throws IOException {
- StringBuilder getStr = new StringBuilder("?");
- if(data != null) {
- for (Map.Entry<String, String> entry : data.entrySet()) {
- getStr.append(entry.getKey())
- .append("=")
- .append(entry.getValue())
- .append("&");
- }
- url += getStr.toString();
- }
- client = new DefaultHttpClient();
- get = new HttpGet(url);
- response = client.execute(get);
- if(response.getStatusLine().getStatusCode() != 200) {
- throw new IOException("Failed to get server response");
- }
- return EntityUtils.toString(response.getEntity());
- }
- }
Add Comment
Please, Sign In to add comment