0

XML データを Web サービスとして持つ Android アプリケーションを使用しています。私の仕事は、HTTP Post を使用して値を投稿し、データを取得してリスト ビューに表示することで、データを追加することです。投稿中に、UTF-8 形式で暗号化する必要があります。

以下にコードを示します。

private String postSyncXML() {
    String url = strMainUrl + strSubUrl;
    HttpClient httpclient = new DefaultHttpClient();


    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs
            .add(new BasicNameValuePair("uid", strUniqueId));
    nameValuePairs.add(new BasicNameValuePair("first_name", strFirstName));
    nameValuePairs.add(new BasicNameValuePair("last_name", strLastName));
    nameValuePairs.add(new BasicNameValuePair("email", strEmail));
    nameValuePairs.add(new BasicNameValuePair("phone", strPhone));
    nameValuePairs.add(new BasicNameValuePair("notes", strNotes));
    nameValuePairs.add(new BasicNameValuePair("is_sms", strIsSms));
    nameValuePairs.add(new BasicNameValuePair("is_email", strIsEmail));


    UrlEncodedFormEntity form;
    try {
        form = new UrlEncodedFormEntity(nameValuePairs, "UTF-8");
        HttpPost httppost = new HttpPost(url);
Log.d("", "Add Guest URL "+url);
        httppost.setEntity(form);

        HttpResponse response = (HttpResponse) httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        String resp = EntityUtils.toString(resEntity);
        Log.i("Method call", "postSyncXML srv response:" + resp);
        return resp;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

前もって感謝します。

4

1 に答える 1