HttpClient的响应仅XML的一行 [英] HttpClient response only one line of XML

查看:95
本文介绍了HttpClient的响应仅XML的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的HttpClient获取一个XML文件,我在得到整个文档返回(它只返回的XML文件的一行)的问题。所以:

  DefaultHttpClient C =新DefaultHttpClient();
BasicResponseHandler R =新BasicResponseHandler();字符串s = NULL;
尝试
{
    S = c.execute(新HTTPGET(HTTP://localhost/activity.xml),R);
}
赶上(例外五)
{
    e.printStackTrace();
}Log.i(TAG,S);

结果字符串永远只是<?XML版本=1.0编码=UTF-8>

有什么我需要做的,告诉HttpClient的装载整个文件或进程换行符什么? XML是超级简单:

 <?XML版本=1.0编码=UTF-8&GT?;
<项目>
    <组ID类型=整数> 2187< /组ID>
    <图标类型=整数> 2'; /图标>
    <名称> Android和LT; /名称>
    <概要> Android应用程序与LT; /概述>
    <&永久GT; codeBase的< /永久>
    <启动网页>门票< /启动网页>
    <状态>&活跃LT; /状态>
< /项目>


解决方案

如果您通过一个 BasicResponseHandler 作为响应处理,的结果执行应该是整个身体的反应。

如果你得到只是一条线,我的理论是,这是所有的服务器发送。

看看服务器日志,看看当它产生响应体被抛出异常。 (如果你使用的是JSP做例如渲染,引发的异常无法通过HTTP状态code报告给客户,而是客户端将看到带有截断体200响应。)

I'm using HttpClient to fetch an XML file and I'm having issues getting the entire document returned (it only returns one line of the XML file). So:

DefaultHttpClient c = new DefaultHttpClient();
BasicResponseHandler r = new BasicResponseHandler();

String s = null;
try
{
    s = c.execute(new HttpGet("http://localhost/activity.xml"), r);
}
catch (Exception e)
{
    e.printStackTrace();
}

Log.i(TAG, s);

The resulting string is always just <?xml version="1.0" encoding="UTF-8"?>

Is there something I need to do to tell HttpClient to load the entire file or process newlines or something? XML is super simple:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <group-id type="integer">2187</group-id>
    <icon type="integer">2</icon>
    <name>Android</name>
    <overview>android app</overview>
    <permalink>codebase</permalink>
    <start-page>tickets</start-page>
    <status>active</status>
</project>

解决方案

If you pass a BasicResponseHandler as the response handler, the result of execute should be the entire response body.

If you are getting just one line, my theory is that that is all that the server is sending.

Take a look at the server logs to see if an exception is being thrown while it is generating the response body. (If you are using a JSP to do the rendering for example, an exception thrown cannot be reported back to the client via the HTTP status code. Instead the client will see a 200 response with a truncated body.)

这篇关于HttpClient的响应仅XML的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆