我需要使用下面的代碼發佈數據到php文件,它將它保存在一個文本文件中。 我只是不知道如何創建php文件來接收下面的數據並將其保存在文本文件中。 儘可能簡單。用PHP寫文章數據到文件
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("stringData", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringData", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String responseText = EntityUtils.toString(response.getEntity());
tv.setText(responseText);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
<?php $ content = $ _POST ['content']; $ file =「text.txt」; $ Saved_File = fopen($ file,'w'); fwrite($ Saved_File,$ content); fclose($ Saved_File); ?> – 2011-01-20 02:55:10
如果你想獲得一個特定密鑰的值並保存它,那麼是的。如果您只想轉儲原始POST數據(不一定是鍵值對 - 例如它可能是二進制數據),那麼'php:// input'流將會讀取它。這個問題很模糊,並要求「儘可能簡單」..好吧,它並沒有變得更簡單。 – Hamish 2011-01-20 03:03:54