0

您好,我想将我的 gps 坐标和设备 ID 发送到服务器。我正在我的服务器上工作,但只是想知道下面的代码是否足以发布坐标..?

//get device id as following
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        String deviceid = telephonyManager.getDeviceId();



            //this is JSON part to put your information inside it
            String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\",\"deviceid\":\""+deviceid+"\"}}";


            HttpClient httpClient = new DefaultHttpClient();

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


            post.setURI(new URI("http://myserver.com/myphppage.php"));

            // set your post data inside post method    
            post.setEntity(new StringEntity(postData));

            // execute post request here 
            HttpResponse response = httpClient.execute(post);
4

1 回答 1

1

试试看。

基本上它取决于您访问服务器的架构(httphttps),但如果连接不安全,那就差不多了。

于 2012-04-23T05:48:09.003 回答