How to send data from android to server

I am learning to scan ssid and rssi from android, and I can do it, but now I want to send data to the server, so I research that I found the code below

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://101.34.45.45/rawData");

    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("userId", "00-22-68-E8-EC-F1"));
        nameValuePairs.add(new BasicNameValuePair("timestamp", "2010-07-01 11:11:11"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        textView.setText(response.toString());

    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

but now I have a problem when adding some wifi data, the format should be lower

http://101.34.45.45/rawData?data= {"userId": "guest1", "timestamp": "2010-07-01 08:58:23", "wifi": [{"ssid": "guest "," rssi ":" 40 "}, {" ssid ":" guest1 "," rssi ":" 80 "}]},

as it can be done for the wifi parameter, can someone help, I'm still trying to use several varieties,

thank

+3
1

JSON . Google gson JSON.

{"userId":"guest1","timestamp":"2010-07-01 08:58:23","wifi":[{"ssid":"guest","rssi":"40"},{"ssid":"guest1","rssi":"80"}]}

JSON, JSON . JSON, , json.

Google GSON, . .

Class data{

 String userId;
 String timestamp;
 Wifi wifi;
}

Class Wifi{

 String ssid;
 int rssi;
}

json android.

.

+1

Source: https://habr.com/ru/post/1752608/


All Articles