相关疑难解决方法(0)

Android,通过HTTP POST方法发送和接收XML

有一个相关的问题,但我无法清楚地得到答案.

我想POST一个简短的xml代码

<aaaLogin inName="admin" inPassword="admin123"/>
Run Code Online (Sandbox Code Playgroud)

通过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
Run Code Online (Sandbox Code Playgroud)

收到回复有问题.此外,我没有写任何东西来保存收到的XML作为文件.有人可以编写代码片段吗?

xml android http http-post

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

http ×1

http-post ×1

xml ×1