Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.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 httpclient使用url作为参数发送帖子?_Android_Httpclient - Fatal编程技术网

android httpclient使用url作为参数发送帖子?

android httpclient使用url作为参数发送帖子?,android,httpclient,Android,Httpclient,我正在从android向web发送数据,web使用的是httpclient,代码如下 DefaultHttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://host"); List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>(); nvps.add(new

我正在从android向web发送数据,web使用的是httpclient,代码如下

DefaultHttpClient client = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://host");
    List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
    nvps.add(new BasicNameValuePair("method", "signIn"));
    nvps.add(new BasicNameValuePair("email",u));
    nvps.add(new BasicNameValuePair("password",pass));
    UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps,HTTP.UTF_8);
    httppost.setEntity(p_entity);
DefaultHttpClient=newdefaulthttpclient();
HttpPost HttpPost=新的HttpPost(“http://host");
List nvps=new ArrayList();
添加(新的BasicNameValuePair(“方法”、“签名”);
添加(新的BasicNameValuePair(“电子邮件”,u));
添加(新的BasicNameValuePair(“密码”,pass));
UrlEncodedFormEntity p_entity=新的UrlEncodedFormEntity(nvps,HTTP.UTF_8);
httppost.setEntity(p_entity);
我有点困惑,如果这段代码将参数作为参数放入url,比如
url?method=a&email=b&password=c
或者将参数放入post主体中

我应该做的是构造一个指向此url的http post?method=a,在post正文中包含电子邮件和密码参数。根据定义,HttpPost在正文中传递参数,而不是在查询字符串中传递参数。另一方面,HttpGet应该在查询字符串中传递参数。 此外,这里的实体代表主体。

您应该了解。根据定义,HttpPost在主体上传递参数,而不是在查询字符串中传递参数。另一方面,HttpGet应该在查询字符串中传递参数。
此外,这里的实体代表主体。

在同一个请求中混合URL参数和post数据有点令人困惑。这并非闻所未闻,但我建议您使用另一个URL登录,例如,发布用户名和密码

您还应该考虑在HTTP调用周围使用包装器。使用DefaultHttpClient将使您编写的代码比使用Volley或其他优秀工具时多得多。使用Android异步Http客户端(URL和POST参数混合)的示例:


在同一个请求中混合URL参数和post数据有点令人困惑。这并非闻所未闻,但我建议您使用另一个URL登录,例如,发布用户名和密码

您还应该考虑在HTTP调用周围使用包装器。使用DefaultHttpClient将使您编写的代码比使用Volley或其他优秀工具时多得多。使用Android异步Http客户端(URL和POST参数混合)的示例:

也许这能帮你也许这能帮你
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("email", "u");
params.put("password", "pass");
client.post("http://host?method=signIn", params, new AsyncHttpResponseHandler() {
    @Override
    public void onSuccess(String response) {
        // handle response here
    }
});