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.
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();
}
}
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
Finally i found the solution , I used the following code to send the data as a from to server
It may helpful for some one like me.