【发布时间】:2015-03-31 17:00:27
【问题描述】:
我是安卓新手。我搜索了很多,发现了很多代码,但我仍然有问题。
我有一个简单的 php,例如:(它有 两个 变量,例如 q 和 number)
http://domain.tld/post.php
并且将数据发布到这个页面后,会有一个JSON格式的结果。
我想在 php 页面上获得该输出,并在 android 上显示该值(我的意思是我希望在 eclipse 中的变量上拥有该值)
我已经检查了这段代码:
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
但是我不能用这个得到输出。
【问题讨论】:
-
@IndraKumarS 我说。当我发送数据时,我无法获得该页面的 json 输出。焦点关闭:(
-
你能发布你的 json 内容吗?
-
json 没有发送,我有两个字符串发送到该页面,它返回一个 JSON,那么如何在 android 中获取该输出?
-
你如何测试?在设备中还是在模拟器中?....您是从 php 获取 json 数据吗?
-
在设备上,也已经激活了用户许可。我在我的电脑上从 php 获取 JSON。
标签: php android eclipse methods