Sending string containing spaces as response from php to Android

Refresh

April 2019

Views

26 time

2

I want to send string containing spaces from php to Android studio. I am using this onPostExecute(String result) to handle string response containing spaces, but it returns the first word of a sentence.

here is my code-

public class PostData extends AsyncTask<String, Void, String>{
        @Override
        protected  String doInBackground(String... args){
             byte[] result = null;
            String str = " ";
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://192.168.42.98:81/launch2.php");

            try{
                List<NameValuePair> nameValuePairs = new ArrayList<>(1);
                nameValuePairs.add(new BasicNameValuePair("input",str_input ));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                HttpResponse response = httpclient.execute(httppost);
                StatusLine statusLine = response.getStatusLine();
                if(statusLine.getStatusCode()== HttpURLConnection.HTTP_OK){
                    result = EntityUtils.toByteArray(response.getEntity());
                    str = new String(result, "UTF-8");

                }
            }catch(ClientProtocolException e){
                //TODO
                tv_result.setText(e.getMessage());
            }
            catch(IOException e){
                //TODO
                tv_result.setText(e.getMessage());
            }
            return str;
        }
        protected void onPostExecute(String result){
            for(String word : result.split(" ")) {
                tv_result.setText(word);
            }
        }
    } 

here is my php code-

<?php
    $var= $_POST["input"];
    $output= exec("python C:\Users\hp\AppData\Local\Programs\Python\Python36\Stem.py .$var");
    echo $output;
?>

0 answers