dtvpl739577 2012-04-09 16:59
浏览 26

从Android发布XML数据并返回PHP

I am doing a php webserver that have communication with android phone. And android phone mainly collect location information and send to webserver while location is updated.

the code below is studied online and i cannot understand them well.

I AM NOT SURE HOW TO READ THE XML FORMAT DATA IN PHP.

most of the example use Parser and SimpleXML, but they mostly know the xml file name, however my code seems no naming of the xml file. And i don't know how to do.

code that connect the php webservice, generate xml file and send.

private String postLocation(double lat, double lng){
    HttpPost httpPost = new HttpPost(url);
    try {
        StringBuilder sb = new StringBuilder();

        sb.append("<Location>");
        sb.append("<lat>");
        sb.append(lat);
        sb.append("</lat>");
        sb.append("<lng>");
        sb.append(lng);
        sb.append("</lng>");
        sb.append("</Location>");

        StringEntity entity = new StringEntity(sb.toString(), "UTF-8");
        httpPost.setEntity(entity);  
        httpPost.addHeader("Accept", "application/xml");
        httpPost.addHeader("Content-Type", "application/xml");

        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse httpResponse = 
            (HttpResponse) httpclient.execute(httpPost);

        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            String strResult = EntityUtils.toString(httpResponse
                    .getEntity());
            //return entity.toString();
            return strResult;
        }
    catch(exception.........){}
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?