How to send data as a form via HttpPost to server in Android?

pret

New Member
I am working on an android project in which i need to send two xml as parameters to server using post method(i.e. i want to send as form). I am tried to send data by using following code but its not working. No data in the remote database.\[code\]private void postFormData(List<DataItem> ti,String ex,String getExpensesXml){ //Create a new Http Client HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); try{ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("sync","true")); nameValuePairs.add(new BasicNameValuePair("tt",ti)); nameValuePairs.add(new BasicNameValuePair("te",ex)); UrlEncodedFormEntity form; form = new UrlEncodedFormEntity(nameValuePairs,"UTF-8"); httppost.setEntity(form); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); String line = EntityUtils.toString(entity); System.out.println(line);} catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }\[/code\]I couldn't find what was the problem. It would be great if anyone manage to find the problem and suggest me the solution.I have two more question?Am i trying the correct code?Is there any other way to send xml data to server via Form?Thanks in advance
 
Back
Top