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

試してみてください。

http基本的には、サーバー(または)にアクセスするスキーマによって異なりますhttpsが、接続が保護されていない場合は、それで十分です。

于 2012-04-23T05:48:09.003 に答える