I am parsing an xml file.
One of the method is below :
public static String getXML(){
String line = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://p-xr.com/xml/");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (MalformedURLException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (IOException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
}
return line;
}
Here, I want to replace
HttpPost httpPost = new HttpPost("http://p-xr.com/xml/");
by
HttpPost httpPost = new HttpPost("http://127.0.0.1/myfile.xml");
As i can browse http://127.0.0.1/myfile.xml in my browser.
But when i write this address to above code it doenst work.
why ?
My project requires http method to access xml file.
Use 10.0.2.2 in this case, check out Emulator Networking.