我的问题是:如何使用 HttpPost 调用 php?
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("www.example.de/mySkript.php");
final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("param1", "value1"));
nameValuePairs.add(new BasicNameValuePair("param2", "value2"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
final HttpResponse response = httpclient.execute(httppost);
我们发现了这个......但我们不想将参数/值发送到 PHP,因为如果您通过 URL 调用我们的 PHP 计数 +1。任何代码只调用PHP?
谢谢 :)
编辑:PHP是:
<?php
$userdatei = fopen ("test.txt","r");
$zeile = fgets($userdatei, 500);
$zeile++;
fclose($userdatei);
$schreiben = fopen ("test.txt","w");
fwrite($schreiben, $zeile);
fclose($schreiben);
?>
并使用此代码:
public static HttpResponse hitUrl(String url) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
return response;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
并调用它:
hitUrl("http://example.de/test.php");
这是正确的吗?