我已经设置了一个AsyncTask
来创建AndroidHttpClient
并调用Execute
,并提供了我提供的HttpPost
和BasicHttpContext
对象。我像这样设置HttpPost
:
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);
当我执行命令时,它检索登录页面而不是登录结果。在服务器端监视了进程之后,这似乎是因为HTTP请求到达时没有附加参数!那我想念什么呢?
最佳答案
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));
关于java - 为什么我调用Execute时我的AndroidHttpClient不发送参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17152713/