您可以使用类似的代码下面的代码片段:
HttpClient httpclient = new DefaultHttpClient();
String responseXml = null;
StringEntity se = "test string to be sent to the server";
HttpPost httppost = new HttpPost(temp);
try {
se.setContentType("text/soap+xml");
httppost.setEntity(se);
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
responseXml = EntityUtils.toString(resEntity);
Log.d("Response XML", responseXml);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
Log.e(TAG,e.getMessage());
} catch (ClientProtocolException e) {
Log.e(TAG,e.getMessage());
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
} catch (Exception e){
e.printStackTrace();
Log.e(TAG,e.getMessage());
}
我用这个代码到一个XML发送到服务器。您可以替换您想要在se变量中发送的内容。