1、StringEntity

try{

HttpPost httpPost = new HttpPost(url);

//param参数,可以为param="key1=value1&key2=value2"的一串字符串,或者是jsonObject

String param1="key1=value1&key2=value2"

JSONObject param2= new JSONObject();

param2.put("key1", "value1");

param2.put("key2t"," value2");

StringEntity stringEntity = new StringEntity(param1);

StringEntity stringEntity = new StringEntity(param2.toString());

stringEntity.setContentType("application/x-www-form-urlencoded");

httpPost.setEntity(stringEntity);

HttpClient client = new DefaultHttpClient();

HttpResponse httpResponse = client.execute(httpPost);

String result = EntityUtils.toString(httpResponse.getEntity(), HTTP.UTF_8);

} catch(IOException e){

}

2、UrlEncodedFormEntity

List<NameValuePair> pairs = new ArrayList<NameValuePair>();

NameValuePair pair1 = new BasicNameValuePair("supervisor", supervisorEt.getEditableText().toString());

NameValuePair pair2 = new BasicNameValuePair("content", superviseContentEt.getEditableText().toString());

NameValuePair pair3 = new BasicNameValuePair("userId", String.valueOf(signedUser.getId()));

pairs.add(pair1);

pairs.add(pair2);

pairs.add(pair3);

httpPost.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8))

http post 方法传递参数的2种方式的更多相关文章

  1. Delphi过程函数传递参数的几种方式

    Delphi过程函数传递参数的几种方式  在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out. 另一种不加修饰符的为默认按值传递参数. 一.默认方式以值方式传递参数 proced ...

  2. asp传递参数的几种方式

    把下列代码分别加入a.asp和b.asp的<body></body>中,点提交,就可以将a.asp文本框的内容传给b.asp并显示出来 a.ASP <form actio ...

  3. 【delphi】Delphi过程、函数传递参数的八种方式

    Delphi过程函数传递参数的八种方式

  4. vue-router传递参数的几种方式

    参考资料:vue.js官网  博客 vue-router传递参数分为两大类 编程式的导航 router.push声明式的导航 <router-link>编程式导航传递参数有两种类型:字符串 ...

  5. vue-router 传递参数的几种方式

    本文转载自:https://blog.csdn.net/crazywoniu/article/details/80942642 vue-router传递参数分为两大类 编程式的导航 router.pu ...

  6. shell 函数传递参数的几种方式

    1.最近总结了 shell 中 function 的传递变量的几种方式 1.传递单个变量 2.传递数组变量   #!/bin/bash   #trying to pass an variable.   ...

  7. Delphi过程函数传递参数的八种方式

    今天一同事问我为什么有些过程函数里面有Var而有些没有,不解,遂到网上百度,得解.快哉,快哉. 在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out.另一种不加修饰符的为默认按值传 ...

  8. spring mvc从前台往后台传递参数的三种方式

     jsp页面: 第一种:使用控制器方法形参的方式(常用) 第二种:使用模型传参的方式(如果前台往后台传递的参数非常多,如果还使用形参的方式传递,非常复杂.我们可以使用模型传参的方式,把多 个请求的参数 ...

  9. JSP中页面向Action传递参数的几种方式

    <form name="ThisForm" method="POST" action="index.jsp"> form是表单, ...

随机推荐

  1. SQL Server数据库常用的T-SQL命令

    1. 查看数据库的版本 select @@version 2.查看数据库所在机器操作系统参数 exec master..xp_msver 3. 查看数据库启动的参数 sp_configure 4.查看 ...

  2. print 和 println的区别

    println 输出字符后,下一个输出的字符会换行展示 print 输出字符后,下一个输出字符不会会换展示

  3. Java-Runoob-高级编程:Java 网络编程

    ylbtech-Java-Runoob-高级编程:Java 网络编程 1.返回顶部 1. Java 网络编程 网络编程是指编写运行在多个设备(计算机)的程序,这些设备都通过网络连接起来. java.n ...

  4. 操作系统-服务器-百科:Windows Server

    ylbtech-操作系统-服务器-百科:Windows Server Windows Server是微软在2003年4月24日推出的Windows 的服务器操作系统,其核心是Microsoft Win ...

  5. [转]SVN 乱码问题

    以下来自:http://godchenmeng.iteye.com/blog/797727 最近研究SVN.发现在创建补丁包的时候出现这种情况. 在文件顶部不论是什么代码都会变成乱码.在文件中如果有注 ...

  6. 04:Sysbench压测-innodb_flush_log_at_trx_commit,sync_binlog参数对性能的影响

    目录 sysbench压测-innodb_flush_log_at_trx_commit,sync_binlog参数对性能的影响 一.OLTP测试前准备 二.MySQL 数据落盘的过程 三.参数说明 ...

  7. C# List泛型转换,int,string 转字符,转数组

    List转字符串 List<string> List = new List<string>(); string strArray = string.Join(",&q ...

  8. “,”、“natural join”、“natural left outer join”、“natural right outer join”的用法总结

    “,”:代表笛卡尔积: “natural join”:代表自然连接,即同名列等值连接: “natural left outer join”:表示左外连接: “natural right outer j ...

  9. socket通信循环

    server-----------------#!/usr/bin/env python # encoding: utf-8  # Date: 2018/6/5 import socket phone ...

  10. ubuntu时区设置

    local-gen zh_CN.UTF-8 UTF-8 /var/lib/locales/supported.d/local可以看到如下内容: zh_CN.UTF-8 UTF-8 en_US.UTF- ...