RestTemplate 发送Post 多个参数请求
MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
requestEntity.add("clientFlag", clientFlag);
requestEntity.add("xml", xml);
requestEntity.add("verifyData", strMd5);
String s = REST_TEMPLATE.postForObject("http://10.10.129.19/svsr/Receive.asmx/OrderXML", requestEntity, String.class);
!!
最直接的方法就是 写个类吧!!
可惜了 JAVA 没有 c# 中 匿名类 这个东西啊
var news = new { title="特大喜讯",author="夕阳眼",postdate="3013-10-9",msg="今晚公布"};
补充:
设置请求头:
MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
postParameters.add("userCode", "291974");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/x-www-form-urlencoded");
HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers); String data= restTemplate.postForObject("http://10.10.12.27:9000/Criteria", r, String.class);
System.out.println(data);
注意:
RestTemplate 会对请求头判断,会更具请求头不通走不同的逻辑。默认是 text/html /*
如果是 application/x-www-form-urlencoded 这个请求头 会对数据镜像 url 编码。
不可以传递 非 字符串类型的数据!!
关于 HttpEntity 这个对象的一点说明
HttpEntity 就是存放 两个字段数据 一个是请求数据 一个是请求头! 从定义上就可以看到 虽然可以 POST 等 提交from 数据 但是好是推荐使用实体类型来传递 HTTP 请求数据。
public class HttpEntity<T> {
private final HttpHeaders headers;
private final T body;
public HttpEntity(T body, MultiValueMap<String, String> headers) {
this.body = body;
HttpHeaders tempHeaders = new HttpHeaders();
if (headers != null) {
tempHeaders.putAll(headers);
}
this.headers = HttpHeaders.readOnlyHttpHeaders(tempHeaders);
}
}
RestTemplate 发送Post 多个参数请求的更多相关文章
- 使用RestTemplate发送post请求,请求头中封装参数
最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败.中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...
- RestTemplate发送请求并携带header信息 RestTemplate post json格式带header信息
原文地址: http://www.cnblogs.com/hujunzheng/p/6018505.html RestTemplate发送请求并携带header信息 v1.使用restTempl ...
- RestTemplate发送HTTP、HTTPS请求
RestTemplate 使用总结 场景: 认证服务器需要有个 http client 把前端发来的请求转发到 backend service, 然后把 backend service 的结果再返 ...
- RestTemplate 发送post请求
springboot使用restTemplate post提交值 restTemplate post值 post提交有 FormData和Payload 两种形式: 第一种是formdata形式,在h ...
- 使用RestTemplate发送post请求
最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败,中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...
- JAVA携带参数(带有请求参数,请求头参数)直接发送POST请求
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcl ...
- Spring RestTemplate中几种常见的请求方式GET请求 POST请求 PUT请求 DELETE请求
Spring RestTemplate中几种常见的请求方式 原文地址: https://blog.csdn.net/u012702547/article/details/77917939 版权声明 ...
- 使用RestTemplate发送multipart/form-data格式的数据
现有业务场景需要使用RestTemplate发送一个post请求,请求格式为multipart/form-data的,可以使用以下方法: public Object sendRequest(Objec ...
- [Socket网络编程]由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。
原文地址:http://blog.sina.com.cn/s/blog_70bf579801017ylu.html,记录在此方便查看 解决办法: MSDN的说明: Close 方法可关闭远程主机连接, ...
随机推荐
- 快学Scala-第九章 文件和正则表达式
知识点: 1.读取文件中的所有行,可以调用scala.io.Source对象的getLines方法: import scala.io.Source val source = Source.from(& ...
- fzu Problem - 2232 炉石传说(二分匹配)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...
- SVM支持向量机算法
支持向量机(SVM)是另一类的学习系统,其众多的优点使得他成为最流行的算法之一.其不仅有扎实的理论基础,而且在许多应用领域比大多数其他算法更准确. 1.线性支持向量机:可分情况 根据公式(1)< ...
- Angular服务器通信之:$http
$http服务提供了浏览器XMLHttpRequest对象的封装,并且作为Angular中和后台服务通信的底层服务,在此之上Angular还提供了一个可选模块ngResource支持与RESTFul的 ...
- PowerDesigner中逆向工程将数据库中comment赋值到name
'------------------------------------------------------------ ' '脚本功能: ' PowerDesigner中逆向工程完成后,将数据库中 ...
- MVC3 Razor 根据不同页面使用不同Layout
_ViewStart.cshtml运行于每一Page前, 所以通常在这里先设置Layout 下面代码为特定的controller指定Index,Edit,Create的模板 即Index对应 _ ...
- '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "AttentionController" nib but the view outlet was not set.'
问题出现原因: 先创建控制器的.h与.m文件,后来创建了相应的xib文件,运行后出现这个问题. 解决办法:
- JS读RSS
<html> <head> <title>javascript读取RSS数据</title> <META content="t ...
- Mac 生产力探究
转载自:http://devtian.me/2015/04/15/about-my-productivity-tool-in-MacOSX/ ##密码管理器 1Password 1Password 是 ...
- (转)Hadoop之常见错误集锦
Hadoop之常见错误集锦 下文中没有特殊说明,环境都是CentOS下Hadoop 2.2.0.1.伪分布模式下执行start-dfs.sh脚本启动HDFS时出现如下错误: ...