不能得到的HttpParams与Postrequest工作 [英] Can't get HttpParams working with Postrequest

查看:289
本文介绍了不能得到的HttpParams与Postrequest工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从Android的API获得的HttpParams-东西的工作。

我只是wan't发送一些简单的参数与我Postrequest。一切工作正常,除了参数。在code的参数设置为postrequest:

 的HttpParams PARAMS =新BasicHttpParams();
params.setParameter(密码,秘密);
params.setParameter(姓名,testuser的);
postRequest.setParams(PARAMS);
 

看来这code不加入任何参数可言,因为服务器总是回答,那我请求缺少名 - 参数。

的究竟是怎样按预期工作的一个例子:

 的ArrayList<的NameValuePair> postParameters =新的ArrayList<的NameValuePair>();
postParameters.add(新BasicNameValuePair(姓名,testuser的));
postParameters.add(新BasicNameValuePair(密码,秘密));
UrlEn codedFormEntity formEntity =新UrlEn codedFormEntity(postParameters);
postRequest.setEntity(formEntity);
 

不过,我想用一个版本的第一个例子,因为它更容易阅读和理解。<​​/ P>

任何暗示,真是AP preciated!

解决方案

在我有同样的问题,我解决它以同样的方式像你一样......我记得我发现了一些话题,为什么这是不工作。这是一些关于Apache的库实现在服务器端。

可惜我找不到话题了,但如果我是你,我只想离开它的工作,不会太在乎的code中的雅,可能导致没有太多你可以做的,如果可以的话,这是不切实际的。

I can't get the HttpParams-stuff from the Android-API working.

I just wan't to send some simple Parameters with my Postrequest. Everything is working fine, except for the parameters. The code to set the parameters to the postrequest:

HttpParams params = new BasicHttpParams();
params.setParameter("password", "secret");
params.setParameter("name", "testuser");
postRequest.setParams(params);

It seems that this code isn't adding any parameter at all, as the server always answer, that my request is missing the "name"-parameter.

An example of what is actually working as expected:

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("name", "testuser"));
postParameters.add(new BasicNameValuePair("password", "secret"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
postRequest.setEntity(formEntity);

But I would like to use a version of the first example, as it is easier to read and understand.

Any hint is really appreciated!

解决方案

Once I had the same issue, and I solved it the same way as you did... I remember I found some topic about why that wasn't working. It was something about Apache's library implementation on the server side.

Unfortunately I can't find that topic now, but if I were you I would just leave it working and wouldn't worry so much about the "elegance" of the code, cause probably there isn't much you can do, and if you can, it's not practical at all.

这篇关于不能得到的HttpParams与Postrequest工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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