HttpPost链接解析网络服务器xml(response.getStatusLine().getStatusCode()==200链接成功)

HttpPost链接解析xml,response.getStatusLine().getStatusCode()==200链接成功,==500失败。

public class XmlPullParserBase {


	private static final String TAG = "XmlPullParserBase";


	public static XmlPullParser getUriXmlPullParser(String url,
			AndroidHttpClient mHttpClient) {


		XmlPullParser parser = null;
		try {
			XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
			factory.setNamespaceAware(true);
			parser = factory.newPullParser();
		} catch (XmlPullParserException e) {
			Log.e(TAG, "Unable to create XmlPullParser", e);
			return null;
		}


		InputStream inputStream = null;
		try {
			final HttpPost post=new HttpPost(url);
//			final HttpGet get = new HttpGet(url);
			HttpResponse response = mHttpClient.execute(post);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				final HttpEntity entity = response.getEntity();
				if (entity != null) {
					inputStream = entity.getContent();
				}
			}else{
				return null;
			}
		} catch (IOException e) {
			Log.w(TAG, "Error while retrieving XML file " + url, e);
			return null;
		}


		try {
			if(inputStream!=null){										//xulongheng
			parser.setInput(inputStream, null);
			}
		} catch (XmlPullParserException e) {
			Log.w(TAG, "Error while reading XML file from " + url, e);
			return null;
		}


		return parser;
	}
}



你可能感兴趣的:(HttpPost链接解析网络服务器xml(response.getStatusLine().getStatusCode()==200链接成功))