xml request with authorization on android

abiorsem

New Member
I'm trying to get and xml content from server that requires username and password.I have tried to google alot, but failed to finde something usefull, here is my code and attemt:\[code\]public String getXmlFromUrl(String url) { String xml = null; try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( "usrname", "pass"); httpClient.getCredentialsProvider().setCredentials( new AuthScope(null, -1), credentials); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); xml = EntityUtils.toString(httpEntity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // return XML return xml;}\[/code\]
 
Back
Top