I am trying to get data from a URL in my localhost to an android app. but I always get fileNotFOundException with this URL
however, when I use another test json data online it works fine for example with this URL http://ift.tt/2kgpquH
This is my android code which I call inside a class that extends the asyntask
public String newServerRequest(String uri)
{
HttpURLConnection connection = null;
BufferedReader reader = null;
int resCode=0;
try {
URL url = new URL(uri);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
resCode=connection.getResponseCode();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
Log.d("Response Laminjanneh: ", "> " + line +" "+resCode); //here u ll get whole response...... :-)
}
String finalObj=buffer.toString();
JSONObject parentObj= new JSONObject(finalObj);
//JSONArray jArray= parentObj.getJSONArray(0);
String name = parentObj.getString("otherkey");
String fname = parentObj.getString("key");
return name+" == "+fname;
} catch (MalformedURLException e) {
e.printStackTrace();
Log.d("Response janneh 1 : ", "> " + e.getMessage()+" "+resCode);
}
catch (IOException e) {
e.printStackTrace();
Log.d("Response janneh 2 : ", "> " + e.getMessage()+" "+resCode);
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
this is my laravel controller that is giving me the the JSOn data
public function questionairename($pcodenumber)
{
$questionaireName= Questionaire_name::where('project_code_number','=',$pcodenumber)->get();
return json_encode($questionaireName);
}
Thanks!!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kwi5FJ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire