Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的Httpost_Android - Fatal编程技术网

android中的Httpost

android中的Httpost,android,Android,我想向android中的php页面发送用户名和密码。 如何使用httpost实现这一点 i、 e我想在PHP页面中使用POST获取值。 请给我举个例子。 谢谢这也许是你想要的(评论是法语的,对不起) 这可能是你想要的(评论是法语的,对不起) HttpClient client = new HttpClient(); HttpClientParams clientParams = new HttpClientParams(); clientPara

我想向android中的php页面发送用户名和密码。 如何使用httpost实现这一点 i、 e我想在PHP页面中使用POST获取值。 请给我举个例子。
谢谢

这也许是你想要的(评论是法语的,对不起)


这可能是你想要的(评论是法语的,对不起)

        HttpClient client = new HttpClient();

        HttpClientParams clientParams = new HttpClientParams();
        clientParams.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
        client.setParams(clientParams);

        // Le HTTPMethod qui sera un Post en lui indiquant l'URL du traitement du formulaire
        PostMethod methode = new PostMethod("http://mywebsite/php/messages.php");
        // On ajoute les parametres du formulaire
        methode.addParameter("password", "my_password");
        methode.addParameter("user_name", userName);
        // Le buffer qui nous servira a recuperer le code de la page
        BufferedReader br = null;
        String txt = null;
        try
        {
            // http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpStatus.html
            int retour = client.executeMethod(methode);
            // Pour la gestion des erreurs ou un debuggage, on recupere le nombre renvoye.
            //System.out.println("La reponse de executeMethod est : " + retour);
            br = new BufferedReader(new InputStreamReader(methode.getResponseBodyAsStream()));
            String readLine;


            // Tant que la ligne en cours n'est pas vide
            while(((readLine = br.readLine()) != null))
                {
                    txt+=readLine;
                }
        }
        catch (Exception e)
        {
            System.err.println(e); // erreur possible de executeMethod
        }
        finally
        {
        // On ferme la connexion
        methode.releaseConnection();
        if(br != null)
            {
            try
                {
                br.close(); // on ferme le buffer
                }
            catch (Exception e) { /* on fait rien */ }
            }
        }