如何在Android上只发送带有http Post的字符串?

时间:2013-05-07 14:51:27

标签: android

我需要将一个字符串发送到服务器,但我知道的唯一方法是使用namevaluepairs,但是发送密钥和值我只想发送一个字符串,我该怎么做?

HttpClient httpclient = new DefaultHttpClient();
                        HttpPost httppost = new HttpPost("http://10.0.2.2:1455/Android/Android.svc/GetCompanyBusinessAreas");


                        try 
                        {           
                         List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                         nameValuePairs.add(new BasicNameValuePair("", companhiaIdS));




                         httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                         Log.i("Enviando:", nameValuePairs.toString());


                        // Execute HTTP Post Request
                            HttpResponse response = httpclient.execute(httppost);
                            Log.i("Resposta:", response.getEntity().toString());
                            HttpEntity responseEntity = response.getEntity();

我可以使用什么代替namevaluepairs,因为它发送一个列表而服务器只需要一个字符串?

1 个答案:

答案 0 :(得分:1)

httppost.setEntity(new StringEntity("your string"));