0

I have created an Android+iOS app, that uses API to retrieve some content in JSON format. Everything was working well until I migrated all my dedicated server to a new one. In new server, the two apps are no more able to get the JSON as before. When the app is supposed to call API, the app crashes some errors like:

org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:160)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at com.krown.eat_out.libraries.JSONParser.getJSONFromUrl(JSONParser.java:43)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at com.krown.eat_out.libraries.UserFunctions.confirmDeal(UserFunctions.java:161)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at com.krown.eat_out.ScreenSlidePageFragment$ConfirmDeal.doInBackground(ScreenSlidePageFragment.java:466)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at com.krown.eat_out.ScreenSlidePageFragment$ConfirmDeal.doInBackground(ScreenSlidePageFragment.java:440)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
07-13 16:12:11.518 4663-4944/com.krown.eat_out W/System.err:     at java.lang.Thread.run(Thread.java:818)

I think it's related with server, but I can't figure out what's the problem. I can't find any info about that in logs..

Here is my code in Android app:

public JSONObject confirmDeal(int valueStartIndex, String deal_id,String imei,String imsi,String android_id){
   Log.d("Krown", "UserFunctions >> confirmDeal 1");
   webService = URLApi+service_confirm_deal+param_deal_id+deal_id+"&"+param_imei+imei+"&"+param_imsi+imsi+"&"+param_android_id+android_id;
   JSONObject json = jsonParser.getJSONFromUrl(webService);
   Log.d("Krown", "UserFunctions >> confirmDeal >> webService: "+webService);
   Log.d("Krown", "UserFunctions >> confirmDeal 2");
   return json;
}

The app crashes at this moment:

webService = URLApi+service_confirm_deal+param_deal_id+deal_id+"&"+param_imei+imei+"&"+param_imsi+imsi+"&"+param_android_id+android_id;
        JSONObject json = jsonParser.getJSONFromUrl(webService);

Any idea how I can solve that? I don't know where I am supposed to search for a solution...

EDIT

Here is what I get from server when trying to fetch JSON

07-13 16:32:45.049 12434-12465/com.krown.eat_out I/TAG: Server Response :: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /eat_out/api/currency was not found on this server.</p><hr><address>Apache/2.4.18 (Ubuntu) Server at dev.krown.ch Port 80</address></body></html>
07-13 16:32:45.103 12434-12465/com.krown.eat_out I/TAG: Server Response :: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /eat_out/api/latest_deals_day was not found on this server.</p><hr><address>Apache/2.4.18 (Ubuntu) Server at dev.krown.ch Port 80</address></body></html>
07-13 16:32:45.155 12434-12465/com.krown.eat_out I/TAG: Server Response :: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /eat_out/api/latest_deals_night was not found on this server.</p><hr><address>Apache/2.4.18 (Ubuntu) Server at dev.krown.ch Port 80</address></body></html>

What is thats? I have several websites installed, everything is working well except this API..

EDIT 2

The url I am trying to call is something like that:

http://mywebsite.com/eat_out/api/confirm_deal?deal_id=&imei=000000000000000&imsi=310260000000000&android_id=b798c307f7d128f4

EDIT 3

The URL http://mywebsite.com/eat_out/api/confirm_deal is not reachable, may be it's related.. :(

Not Found

The requested URL /eat_out/api/confirm_deal was not found on this server.

Is possible that this issue could be related with a missing extension in PHP configuration or with PHP directly? I am using PHP 7 in new server.

Kr1
  • 1,269
  • 2
  • 24
  • 56
  • What response getting from server ? – ρяσѕρєя K Jul 13 '16 at 16:22
  • i think you parse `JSONArray` into `JSONObject` sho me your responce from server. – Jaydip Jul 13 '16 at 16:24
  • What is line number 43 in JSONParser.java? – ρяσѕρєя K Jul 13 '16 at 16:26
  • How can I show the response from the server? I think it's rather related with php or apache2 installation. – Kr1 Jul 13 '16 at 16:26
  • Your server is not replying with JSON, the `Value – Bonatti Jul 13 '16 at 16:27
  • @ρяσѕρєяK, it's jObj = new JSONObject(str); – Kr1 Jul 13 '16 at 16:27
  • Paste the response you get from the server in your variable using debug in your android project, by getting a `log.v` of it. – Shadab K Jul 13 '16 at 16:28
  • use `Log.i("TAG","Server Response :: "+str);` before `jObj = new JSONObject(str);` line and check in logcat what string getting from server – ρяσѕρєя K Jul 13 '16 at 16:29
  • @ShadabK, I don't get any response, the app crashes when I do "JSONObject json = jsonParser.getJSONFromUrl(webService);" – Kr1 Jul 13 '16 at 16:31
  • @ρяσѕρєяK, I updated my post to show the response I am getting – Kr1 Jul 13 '16 at 16:35
  • @118218 Try to debug and get the output from your `HttpUrlConnection` declarations where you get the first response. Else the mistake is you are not getting the json response instead you are getting a .json file as a response which is making the output as a HTML response, in-return downloading the .json file and a blank or null server response with HTML content only. – Shadab K Jul 13 '16 at 16:36
  • @ShadabK, Actually the response it's a crappy "Page not found" – Kr1 Jul 13 '16 at 16:36
  • @118218 Add the url you are trying to access in your post with some changes if you would like to preserve your data – Shadab K Jul 13 '16 at 16:37
  • @118218 Verify your url, if it is missing any parameters to get the JSON response. – Shadab K Jul 13 '16 at 16:37
  • @ShadabK, no I didn't change anything in apps, only the server has changed. The two apps were working fine for several months – Kr1 Jul 13 '16 at 16:40
  • Your server might not be hosting this webapis properly, have a look at the hosted apps – Shadab K Jul 13 '16 at 16:55

0 Answers0