开发者

Android, SAX and Cookies: How to add a cookie when trying to parse XML from an URL

I want to parse the result of a specific URL using Simple Ajax for XML. This is basically my Code:

URL link = new URL(url); // url is just a string represe开发者_如何学运维nting the url
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(myHandler);  // the class of myHandler extends from DefaultHandler
InputStream stream = link.openStream();
InputSource inputSource = new InputSource(stream);
inputSource.setEncoding("ISO-8859-1");
 xr.parse(inputSource);

But how can I add a cookie? I know I can add Cookies to HttpClients like so:

BasicClientCookie cookie = new BasicClientCookie("access_token", accessToken);
mHttpClient.getCookieStore().addCookie(cookie);
HttpGet request = new HttpGet("www.reeple.net/xml/login/" + uid);
mHttpClient.execute(request);

But how can I add a cookie to a request, that is handlet by the SAX-Api?


Step #1: Use HttpClient to retrieve the XML as a string, using whatever cookies you want

Step #2: Use SAX to parse the string retrieved by HttpClient

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜