2013-04-27 56 views
0

我已經得到了我需要的座標和其他參數。我用這張貼到我的服務器:我如何在服務器上訪問(請參閱)我從Android發送到服務器的GPS座標?

       String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\",\"speed\":\""+speed+"\"}}"; 


           HttpClient httpClient = new DefaultHttpClient(); 

           // Post method to send data to server 
           HttpPost post = new HttpPost(); 


           try { 
            post.setURI(new URI("http://10.0.2.15:80")); 
           } catch (URISyntaxException e1) { 
            // TODO Auto-generated catch block 
            e1.printStackTrace(); 
           } 

           // set your post data inside post method  
           try { 
            post.setEntity(new StringEntity(postData)); 
           } catch (UnsupportedEncodingException e1) { 
            // TODO Auto-generated catch block 
            e1.printStackTrace(); 
           } 

           // execute post request here 
           try { 
            HttpResponse response = httpClient.execute(post); 
           } catch (ClientProtocolException e1) { 
            // TODO Auto-generated catch block 
            e1.printStackTrace(); 
           } catch (IOException e1) { 
            // TODO Auto-generated catch block 
            e1.printStackTrace(); 
           } 

我怎麼確定它已經到服務器?我如何看到服務器上的座標? 我想將這些值保存在數據庫中並處理它們。

回答

0

當服務器接收你的數據只是將它們保存在數據庫中,並作爲結果,一切都被保存,(通過服務器從客戶端接受數據)返回相同的數據,您的客戶端程序。

使用這種方法,你一定會在:

  1. 服務器接受您的數據
  2. 服務器接受正確的數據
  3. 服務器保存的數據

例:

假設我想向服務器發送'Name = Michael'參數。當服務器接受參數名稱時,我將它保存在數據庫中,並將相同的參數返回給客戶端 - >'Name = Michael'。因此,您可以確保服務器獲取參數。

+0

但我如何確認它已經到服務器? – user1698122 2013-04-28 14:53:55

+0

據我所知,你想知道服務器是否從客戶端獲取數據,對嗎?如果是這樣,只要發回你收到的東西!可能是我誤會了。你可以寫更多的細節或舉例。 – 2013-04-28 15:06:56

相關問題