try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://somepostaddress.com";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user", "kris"));
params.add(new BasicNameValuePair("pass", "xyz"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
這是我在http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests發現的代碼。之後我只會在php中使用簡單的POST方法變量,對吧?使用PHP GET和POST在Android編程
示例:
$ user = $ _ POST ['user']; $ pass = $ _ POST ['pass'];
但是,當我執行代碼時,PHP只顯示0。我可以知道如何解決它嗎?感謝
P/S:SRY的英語不好
感謝您的幫助。但是,它適用於仿真器嗎?值從來沒有顯示在我的PHP文件.... – Sam 2010-12-17 02:18:41
我看到你解決了它:) – shein 2010-12-17 08:17:27