예제 #1
0
        public void run() {

          while (false == stopThread) {
            if (true == requestToSendAuthHttp) {
              // send HTTP request here
              // Send Auth request to server here
              {
                Log.d("Anoop", "Connecting to HTTP server");

                // TODO: Add HTTP URL here
                try {
                  httpRestClient = new RestClient("http://192.241.136.52:5000/project/create");
                } catch (Exception e) {
                  e.printStackTrace();
                  Log.d("Anoop", "Unable to connect to HTTP server");
                  return;
                }

                Log.d("Anoop", "httpRestClient object " + httpRestClient);

                httpRestClient.AddParam("name", "Anoop");

                try {
                  httpRestClient.Execute(RequestMethod.POST);
                } catch (Exception e) {

                  Log.d("Anoop", "Fatal Unable to send HTTP POST Request " + httpRestClient);

                  e.printStackTrace();
                }

                Log.d("Anoop", "Done... with connection to HTTP server");
              }

              // Obtain ID from the server
              {
                httpResponse = httpRestClient.getResponse();

                Log.d("Anoop", "Response from HTTP server " + httpResponse);
              }

              requestToSendAuthHttp = false;
            }

            try {
              sleep(100);

            } catch (Exception e) {
              e.printStackTrace();
              Log.d("Anoop", "Sleeping for 100 ms ");
            }
          }
          ;
        }
예제 #2
0
        public void run() {

          while (false == stopPerThread) {
            if (true == requestToSendLatHttp) {
              // send HTTP request here
              // Send Auth request to server here
              {
                Log.d("Anoop", "Sending Latlong to HTTP server");

                httpRestClient = new RestClient("http://192.241.136.52:5000/location/create");

                if (null == httpRestClient) {
                  //							txtLat.setText("Error in connecting to server");
                  //							Log.d("Anoop", "Error in connecting to server");
                  //							return;
                }

                Log.d("Anoop", "Adding parameters to the HTTP Request");

                httpRestClient.AddParam("project_id", httpResponse);
                httpRestClient.AddParam("latitude", Double.toString(currLocation.getLatitude()));
                httpRestClient.AddParam("longitude", Double.toString(currLocation.getLongitude()));

                try {
                  //							txtLat.setText("Sending HTTP request");
                  Log.d("Anoop", "Sending HTTP request");
                  httpRestClient.Execute(RequestMethod.POST);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Obtain junk from the server
              {
                httpResponseLat = httpRestClient.getResponse();
                Log.d("Anoop", "Response from HTTP server " + httpResponseLat);
              }

              requestToSendLatHttp = false;
            }

            try {
              sleep(100);

            } catch (Exception e) {
              e.printStackTrace();
              Log.d("Anoop", "Sleeping for 100 ms ");
            }
          }
          ;
        }