Hey there,
I need to post XML Code to the URL: http://www.http.com//(MyIP)/data/changes.xml. I tried a lot some codes I found in tutorals but nothing works. I have this reight now but I always get the Error1 and Error2. Does anyone knows what im doing wrong? I apprechiate every help, thanks!
I need to post XML Code to the URL: http://www.http.com//(MyIP)/data/changes.xml. I tried a lot some codes I found in tutorals but nothing works. I have this reight now but I always get the Error1 and Error2. Does anyone knows what im doing wrong? I apprechiate every help, thanks!
Code:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
httpPostRequest(constructXml());
}
public void onUpdate(View view) {
fewMyXML getMyXML = new fewMyXML();
getMyXML.execute();
temp = getMyXML.actual();
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, temp);
list.setAdapter(adapter);
}
public static void httpPostRequest(String data) {
BufferedReader reader = null;
HttpURLConnection conn = null;
try {
URL url = new URL("http://www.http.com//(MyIP)/data/changes.xml");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
Log.d("post response code", conn.getResponseCode() + " ");
} catch (Exception e) {
e.printStackTrace();
Log.d("Error1", "error1");
} finally {
try {
reader.close();
if (conn != null) {
conn.disconnect();
}
} catch (Exception ex) {
Log.d("Error2", "error2");
}
}
Log.d("Error3", "Error3");
}
public String constructXml(){
//DATA
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <Devices> <Device> <ID>EZR010A49</ID> <HEATAREA nr=\"4\"> <T_TARGET>19</T_TARGET> </HEATAREA> </Device> </Devices>");
return sb.toString();
}
kio$2.read(Okio.java:113)