开发者

Response to android device from server php

开发者 https://www.devze.com 2023-03-06 05:50 出处:网络
I am tiring this for sometime now to send response from server to android & havent been successful so far...

I am tiring this for sometime now to send response from server to android & havent been successful so far... code:

   try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2:80/php/base.php");
          httppost.setEntity(new UrlEncoded开发者_JAVA百科FormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        }catch(Exception e){
         Log.e("log_tag", "Error in http connection "+e.toString());
       } 

    StringBuilder sb;
     try{
      BufferedReader reader = new BufferedReader(new
       InputStreamReader(is,"iso-8859-1"),8);
        sb = new StringBuilder();
          sb.append(reader.readLine() + "\n");
       String line = null;
       while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
        }
       text = sb.toString();
        tv.setText(text);
         is.close();
        }

Cant figure out whats wrong....i cant get response on android emulator ...its just an echo statement on the script...how can i output it on the device.I have tried json too didnt work


you needn't to specify port no. in URL .try with this url "http://10.0.2.2/php/base.php"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号