本文介绍了为什么我的Andr​​oidHttpClient不发送PARAMS当我打电话执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的AsyncTask 设置来创建一个 AndroidHttpClient 并调用执行,用我提供了一个 HttpPost BasicHttpContext 的对象。我设置了 HttpPost 像这样:

  HttpPost myPost =新HttpPost(http://192.168.1.66:8080/login.html);
BasicHttpParams的HttpParams =新BasicHttpParams();
httpParams.setParameter(CMD,登录);
httpParams.setParameter(用户名,测试);
httpParams.setParameter(密码,密码);
myPost.setParams(的HttpParams);

当我执行命令,它会检索登录页面,而不是登录的结果。监控服务器端的过程之后,似乎这是因为HTTP请求没有任何附加PARAMS到来了!所以我缺少什么?


解决方案

  HttpPost后=新HttpPost(http://192.168.1.66:8080/login.html);
            清单<&的NameValuePair GT; namevaluepairs中=新的ArrayList<&的NameValuePair GT;(
                    3);
            nameValuePairs.add(新BasicNameValuePair(CMD,登陆
                    。.getText()的toString()));
            nameValuePairs.add(新BasicNameValuePair(用户名,测试
                    。.getText()的toString()));            nameValuePairs.add(新BasicNameValuePair(密码,密码
                    。.getText()的toString()));            post.setEntity(新UrlEn codedFormEntity(namevaluepairs中));

I've got an AsyncTask set up to create an AndroidHttpClient and call Execute, with a HttpPost and BasicHttpContext objects I provide. I set up the HttpPost like so:

HttpPost myPost = new HttpPost("http://192.168.1.66:8080/login.html");
BasicHttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("cmd", "Login");
httpParams.setParameter("Username", "test");
httpParams.setParameter("Password", "password");
myPost.setParams(httpParams);

When I execute the command, it retrieves the login page instead of the results of logging in. After monitoring the process on the server side, it seems that this is because the HTTP request arrived with no params attached! So what am I missing?

解决方案
            HttpPost post = new HttpPost("http://192.168.1.66:8080/login.html");
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                    3);
            nameValuePairs.add(new BasicNameValuePair("cmd", "Login"
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("Username", "test"
                    .getText().toString()));

            nameValuePairs.add(new BasicNameValuePair("Password", "Password"
                    .getText().toString()));

            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

这篇关于为什么我的Andr​​oidHttpClient不发送PARAMS当我打电话执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:47