This must be something really stupid, trying to solve this issue for a couple of days now and it's really not working. I searched everywhere and there probably is someone with the same problem, but I can't seem to find it.
I'm working on an Android app and this app pulls some xml from a website. Since this website is down a lot, I decided to save it and run it locally. Now what I did;
- I downloaded the kWs app for hosting the downloaded xml file
- I put the file in the right directory and could access it through the mobile browser, but not with my app (same code as I used with pulling it from some other website, not hosted by me, only difference was the URL obviously)
So I tried to host it on my PC and access it with my app from there. Again the same results, the mobile browsers had no problem finding it, but the app kept saying 404 Not Found: "The requested URL /test.xml¶ma=Someone¶mb= was not found on this server."
Note: Don't mind the 2 parameters I am sending, I needed that to get the right stuff from the website that wasn't hosted by me.
My code:
public String getStuff(String name){
String URL = "http://10.0.0.8/test.xml";
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("parama", name));
params.add(new BasicNameValuePair("paramb", ""));
APIRequest request = new APIRequest(URL, params);
try {
RequestXML rxml = new RequestXML();
AsyncTask<APIRequest, Void, String> a = rxml.execute(request);
...
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
That should be working correctly. Now the RequestXML class part:
class RequestXML extends AsyncTask<APIRequest, Void, String>{
@Override
protected String doInBackground(APIRequest... uri) {
HttpClient httpclient = new DefaultHttpClient();
String completeUrl = uri[0].url;
// ... Add parameters to URL ...
HttpGet request = null;
try {
request = new HttpGet(new URI(completeUrl));
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
HttpResponse response;
String responseString = "";
try {
response = httpclient.execute(request);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
// .. It crashes here, because statusLine.getStatusCode() returns a 404 instead of a 200.
The xml is just plain xml, nothing special about it. I changed the contents of the .htaccess file into "ALLOW FROM ALL" (works, cause the browser on my mobile device can access it and shows the correct xml).
I am running Android 4.0.4 and I am using the default browser AND chrome on my mobile device.
I am using MoWeS to host the website on my PC.
Any help would be appreciated and if you need to know anything before you can find an answer to this problem, I'll be more than happy to give you that info.
Thank you for you time!
Cheers.