I am trying to call a restful webservice (that needs to require authentication) from my android app. I am doing this successfully already with a url that does not require authentication, but am not sure of the correct approach to use if I want to set up a url that does require authentication. I am currently consuming xml using a Sax Parser and calling url.openStream() like this:
`
URL url = new URL('MyUnAuthenticatedURL');
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
final QuestionHandler myQuestionHandler = new QuestionHandler();
xr.setContentHandler(myQuestionHandler);
xr.parse(new InputSource(url.openStream()));
handler.post(new Runnable() {
public void run() {
recentQuestions = myQuestionHandler.getResultList();
loadQuestions = false;
fillData();
}
});
`
I read that I should use org.apache.http.impl.client.DefaultHttpClient in order to take advantage of HTTP Basic Authentication using default session cookies, but I don't understand how this should be done in conjunction with the the Sax Parser.
The main goal here is that I want to call a url that requires an authenticated username, and have that url return XML if the username is authenticated with a password.
Can someone point me in the right direction? Thanks!