Android的通话PHP与HTTP-GET [英] Android call PHP with HTTP-GET

查看:131
本文介绍了Android的通话PHP与HTTP-GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:如何调用与HttpPost

My question is: How to call a php with HttpPost?

 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的,因为我们的PHP计数+1,如果你通过URL来调用它。任何code只是调用PHP?

We found this...but we don't want to send Parameters/Values to the PHP because our PHP is counting +1 if you call it through the URL. Any code for just call the 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);
?>

和使用该code:

    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");

这是正确的?

Is this right?

推荐答案

您需要做的HTTP GET请求到服务器,你可以使用这样的:

You need to make HTTP GET request to your server, you can use something like:

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库此服务器的异步调用:

I can also recommend AQuery library for this server asynchronous calls:

HTTP://$c$c.google.com/p/android -query /

这篇关于Android的通话PHP与HTTP-GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆