Hi guys,
So I´m trying to develop an App to control a thermostat. I´m using an API provided by the manufacturer. Here´s a description. I´m already reading an XML from the URL and now I need to post an XML file to a HTTP. I have no Idea how to do this and searched for some solutions. This is my current PostClass method:
In my LogCat it says "Success", ... so my Code seems to be working at first. However when I check the xml file in my Browser it doesn't display the changes. So I´m not sure if the problem is in my Code or if the API is not working properly. Also I´m the API should be sending a respons after sending a post but I don't know how to get this response. Any help on how I can get the push to work and getting the response would be great!
So I´m trying to develop an App to control a thermostat. I´m using an API provided by the manufacturer. Here´s a description. I´m already reading an XML from the URL and now I need to post an XML file to a HTTP. I have no Idea how to do this and searched for some solutions. This is my current PostClass method:
Code:
public class PushData extends AsyncTask{
private final String postUrl = "http://192.168.178.38/data/changes.xml";
private final String postString = " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
" <Devices>\n" +
" <Device>\n" +
" <ID>EZR0114AF</ID>\n" +
" <HEATAREA nr=\"4\">\n" +
" <T_TARGET>18.7</T_TARGET>\n" +
" </HEATAREA>\n" +
" </Device>\n" +
" </Devices>";
@Override
protected Object doInBackground(Object[] objects) {
try {
URL url = new URL(postUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
String body = postString;
OutputStream output = new BufferedOutputStream(conn.getOutputStream());
output.write(body.getBytes());
output.flush();
Log.d("Success", postString);
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
}
return null;
}
}
In my LogCat it says "Success", ... so my Code seems to be working at first. However when I check the xml file in my Browser it doesn't display the changes. So I´m not sure if the problem is in my Code or if the API is not working properly. Also I´m the API should be sending a respons after sending a post but I don't know how to get this response. Any help on how I can get the push to work and getting the response would be great!