1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| HttpURLConnection con;
String urlString="your url"
URL url;
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
e.printStackTrace();
return;
}
try {
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
con.setConnectTimeout(_timeOut);
// con.setRequestProperty("SOAPAction", "\"yoursoapaction\"");
con.setRequestProperty("Content-Type", "application/soap+xml;charset=UTF-8");
con.connect();
} catch (IOException e1) {
e1.printStackTrace();
return;
}
InputStream in = null;
OutputStream out;
byte[] buff;
try
{
out = con.getOutputStream();
buff = event.getHttpBody().getBytes("UTF8");
out.write(buff);
out.flush();
out.close();
in = con.getInputStream();
String s = "";
int numberRead = 1024;
while (numberRead == 1024) {
byte[] buffer = new byte[1024];
numberRead = in.read(buffer);
s += new String(buffer);
}
s = s.trim();// the server response
}
catch(Exception e)
{
e.printStackTrace();
} |
Partager