This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Android and the fly likes Post an XML filt to a Web Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Post an XML filt to a Web Server" Watch "Post an XML filt to a Web Server" New topic
Author

Post an XML filt to a Web Server

Thomas Francl
Greenhorn

Joined: Nov 12, 2011
Posts: 2
I know I'm making a mountain out of a molehill but I just can't get an XML file posted to my web server. I do get a response "BasicHttpResponse@44e809b8". Here's most of my code:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Construct data
String data = null;

HttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.airdynamite.com/newsql.xml");

try {
InputStream is = null;
is = new BufferedInputStream(new FileInputStream("/data/data/samples.employeedirectory/newsql.xml"));
data = is.toString();

httppost.setEntity(new StringEntity(data, "UTF8"));

HttpResponse response = httpClient.execute(httppost);

Toast.makeText(this, "response "+response, Toast.LENGTH_LONG).show();

} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}

Thank you in advance for any suggestions.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
"BasicHttpResponse@44e809b8" is not the response you're getting, it's the result of calling "response.toString()" (which is what using "response" in a string concatenation will do).

The actual response can be obtained via "response.getEntity()", and then working with that object.
Thomas Francl
Greenhorn

Joined: Nov 12, 2011
Posts: 2
Thank you. Does the rest of the code appear correct?
 
jQuery in Action, 2nd edition
 
subject: Post an XML filt to a Web Server
 
Similar Threads
Httppost Problem
OpenYMSG API on android
Trying to POST an XML to php based Web Service via HTTP POST method
Looking for correct data type to take in stream of xml
Application nor run in the background