I'm trying to read at php echo and store it in a string from an android app, cant seem to get it to work. No errors are given, everything works fine when the code is runned in eclipse but for some reason it wont work in android studio, thought maybe someone here could take a look at it and see if i'm missing something!
String login_url = "some url";
String result="";
try{
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("namn","UTF-8")+"="+URLEncoder.encode(,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
Log.d("HTTPSENDER",""+httpURLConnection.getResponseCode());
bufferedWriter.close();
outputStream.close();
// LÄSER FRÅN HEMSIDAN
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
String line="";
while((line = bufferedReader.readLine()) != null){
System.out.println(result);
result += line;
}
//AVSLUTA CONNECTION
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
} catch(Exception e){
e.printStackTrace();
}
so i figured that i could store the output in the string named result and then just use it in a textview or something, but it returns null for some reason when being used in android.
And just for the record, i have been looking through older questions like mine but none have given me much help!