【发布时间】:2015-05-07 14:05:55
【问题描述】:
有一个相关的问题,但我无法清楚地得到答案。
我想发布一个简短的 xml 代码
<aaaLogin inName="admin" inPassword="admin123"/>
通过 HTTP 发送到特定的 URL 地址。 Web 服务将返回给我一个 XML 代码。重要的部分是我将解析收到的 XML,并将其存储为文件。
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.192.131/"); //URL address
StringEntity se = new StringEntity("<aaaLogin inName=\"admin\" inPassword=\"admin123\"/>",HTTP.UTF_8); //XML as a string
se.setContentType("text/xml"); //declare it as XML
httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8");
httppost.setEntity(se);
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient .execute(httppost);
tvData.setText(httpResponse.getStatusLine().toString()); //text view is expected to print the response
接收响应有问题。此外,我没有写任何东西来将接收到的 XML 保存为文件。有人能写个代码sn-p吗?
【问题讨论】:
标签: android xml http http-post