2013-05-07 48 views
0

我需要發送一個字符串到服務器,但我知道的唯一方法是使用namevaluepairs,但發送密鑰和值我只想發送一個字符串,我該怎麼做?如何只發送一個字符串與http Post在Android上?

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
httppost.setEntity(new StringEntity("your string")); 
+0

謝謝:)我不能在任何地方找到它,因爲每個人都使用namevaluepairs中 – 2013-05-07 15:08:29

+0

其無working..and不管我走到哪裏,他們說,你不能發送只是一個字符串或HTTP一個int,你必須發送一個列表或什麼...你能幫我嗎? – 2013-05-08 10:52:13

相關問題