Danke für deine Hilfe!
Also das ist mein Code zum aktuellen stand:
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 data = URLEncoder.encode(postString, "UTF-8");
conn.setRequestProperty( "Content-Type","application/x-www-form-urlencoded" );
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", String.valueOf(data.getBytes().length) );
//OutputStream output = new BufferedOutputStream(conn.getOutputStream());
//output.write(body.getBytes());
//output.flush();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(conn.getOutputStream());
outputStreamWriter.write(data);
outputStreamWriter.flush();
Log.d("Success", data);
InputStream answerStream = conn.getInputStream();
String answer = getAnswer(answerStream);
Log.d("answer", answer);
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
}
return null;
}
public String getAnswer(InputStream is){
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
String currentLine;
try {
while ((currentLine = reader.readLine()) != null){
stringBuilder.append(currentLine);
stringBuilder.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString().trim();
}
}
Alles anzeigen
Habe mir das Video angeguckt aber außer der Fähigkeit die Antwort zu erhalten habe ich nicht viel verändert. Ich bekomme jetzt auch den gleichen String wie du ausgegeben:
Code
%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A+%3CDevices%3E%0A+%3CDevice%3E%0A+%3CID%3EEZR0114AF%3C%2FID%3E%0A+%3CHEATAREA+nr%3D%224%22%3E%0A+%3CT_TARGET%3E18.7%3C%2FT_TARGET%3E%0A+%3C%2FHEATAREA%3E%0A+%3C%2FDevice%3E%0A+%3C%2FDevices%3E
Funktionieren tut es leider immer noch nicht.
Mit Permission meinst du die Internet Berechtigung im manifest?
Die habe ich natürlich gegeben.