我想發送XML到IP。我正在做以下代碼:如何將xml發送到IP並在android中獲取xml響應?
String sMessage = "<SERVER><CONNECT><IP>192.168.10.14</IP><CLIENT_ID>123</CLIENT_ID></CONNECT></SERVER>";
Socket socket = new Socket("192.168.252.148", 34543);
System.out.println("socket connected---: "+socket.isConnected());
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
InputStream in = socket.getInputStream();
out.println(sMessage);
byte[] buffer = new byte[in.available()];
in.read(buffer);
String rMsg = new String(buffer);
System.out.println("rMsg: "+rMsg);
out.close();
in.close();
socket.close();
rMsg總是空的。套接字連接是真實的。爲什麼我沒有得到迴應。我試圖將InputStream更改爲BufferedInputStream,但它沒有幫助。任何解決這個問題的想法都是通過修改這個代碼或者通過創建新想法來解決的提前致謝。