让PHP Echo在Android版 [英] Get PHP Echo in Android

查看:561
本文介绍了让PHP Echo在Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题,从网站接收PHP回声消息。
我有这个code:

I have some problems with Receiving PHP Echo message from an website. I have this code:

HttpClient httpclient=new DefaultHttpClient(); 
   HttpPost httppost=new  HttpPost("http://www.itbstudios.tk/test.php");
   HttpResponse response = httpclient.execute(httppost);
   String str =  EntityUtils.toString(response.getEntity());

我发现这个code和更大量在这里计算器,并且不工作。该应用crahsing在 httpclient.execute();

Internet权限设置在Android清单。

Internet permission is set in android manifest.

PHP的code是只是一个< PHP的echo测试; ?>

Php code is just an <?php echo "test"; ?>

我要建的15 API和HTC设备测试。

I'm building for API 15 and testing on HTC Device.

你们能帮助我吗?
我甚至创造了一个其他项目并粘贴code在创建和我有同样的问题。

Can you guys help me? I even created an other project and paste the code in on create and i have the same problem.

谢谢!

推荐答案

HttpClient的得到了一些错误的API比10.使用HttpURLConnection的更高吧。

HttpClient got some bugs in API higher than 10. Use HttpUrlConnection instead.

GET方法例如:

URL url = new URL("http://www.itbstudios.tk/test.php");
HttpUrlConnection mUrlConnection = (HttpURLConnection) url.openConnection();
mUrlConnection.setDoInput(true);

InputStream is = new BufferedInputStream(mUrlConnection.getInputStream());
String s = readStream(is);

这篇关于让PHP Echo在Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆