我的问题是:如何使用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);我们发现了this...but,我们不想发送参数/值给PHP,因为我们的PHP是+1,如果你通过URL调用它的话。有没有直接调用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");是这样的吗?
发布于 2013-03-10 23:54:49
你需要向你的服务器发出HTTP GET请求,你可以使用如下命令:
public static HttpResponse hitUrl(String url) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
return response;
} catch (Exception e) {
Log.("[GET REQUEST]", "Network exception", e);
return null;
}
}我也可以推荐这个服务器异步调用的AQuery库:
http://code.google.com/p/android-query/
https://stackoverflow.com/questions/15322940
复制相似问题