Im migrazione di un servizio da un normale server di dominio DNS a un unico server IP e questo fornisce un servizio di JSON per la mia app, il problema è che posso recuperare il JSONArray con il seguente codice nel nuovo URL:Impossibile recuperare JSONArray dal server IP ma posso farlo da un normale server?
protected JSONArray doInBackground(String... arg0) {
String reponse;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse responce = httpclient.execute(httppost);
HttpEntity httpEntity = responce.getEntity();
reponse = EntityUtils.toString(httpEntity);
return new JSONArray(reponse);
//With the oldURL I printed the JSON as a string and everithing OK but the new URL returns a null string of JSON
}catch(Exception e){
e.printStackTrace();
}
return null;
}
String newurlexample = "http://111.22.333.44:1234/FOLD/blablabla";
String oldurl = "https:/example.com/FOLD/file.json";
e ottengo il seguente registro:
07-13 17:47:02.142: W/System.err(18824): org.json.JSONException: Value Method of type java.lang.String cannot be converted to JSONArray
07-13 17:47:02.145: W/System.err(18824): at org.json.JSON.typeMismatch(JSON.java:111)
07-13 17:47:02.145: W/System.err(18824): at org.json.JSONArray.<init>(JSONArray.java:96)
07-13 17:47:02.146: W/System.err(18824): at org.json.JSONArray.<init>(JSONArray.java:108)
07-13 17:47:02.146: W/System.err(18824): at com.karlol.***.Doctor_Fragment$GetData.doInBackground(Doctor_Fragment.java:171)
07-13 17:47:02.146: W/System.err(18824): at com.karlol.***.Doctor_Fragment$GetData.doInBackground(Doctor_Fragment.java:1)
07-13 17:47:02.147: W/System.err(18824): at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-13 17:47:02.147: W/System.err(18824): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-13 17:47:02.147: W/System.err(18824): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
07-13 17:47:02.147: W/System.err(18824): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
La mia prima risposta è: perché non stai usando [Volley] (https://www.youtube.com/watch?v=yhv8l9F44qo)? – sonictt1
Assicurati di poter accedere al tuo URL IP e restituisce JSON valido. Stampa anche la variabile "reponse" per vedere cosa restituisce il server – Sharj
l'URL restituisce un JSON valido e la "risposta" restituisce: 'Metodo [POST] Non consentito, per favore assicurati che il REST MEthod [POST] per risorsa [il mio nuovo indirizzo] sia disponibile nell'altro lato! ' –