RestTemplate 发送post请求
springboot使用restTemplate post提交值 restTemplate post值
post提交有 FormData和Payload 两种形式:
第一种是formdata形式,在header参数里可以直接看到
payload则封装成json格式post过去,获取以后需要再解析成实体。
restTemplate post json格式
使用阿里巴巴的json包 com.alibaba.fastjson
代码demo如下:
url='http://posturl';JSONObject postData = new JSONObject();
postData.put("shopid", 1);
JSONObject json = restTemplate.postForEntity(url, postData, JSONObject.class).getBody();
如果要使用post formdata形式则需要
使用RestTemplate发送multipart/form-data格式的数据
复制代码
String url = 'http://posturl';
MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("shopid","1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
return restTemplate.postForEntity(url, request,String.class);
复制代码
对header进行请求头设置,如果不设置也可以直接post那么就是如下的
复制代码
String url = 'http://posturl';
MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("shopid","1");
return restTemplate.postForEntity(url, map,String.class);
RestTemplate 发送post请求的更多相关文章
- 使用RestTemplate发送post请求
最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败,中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...
- 使用RestTemplate发送post请求,请求头中封装参数
最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败.中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...
- RestTemplate 发送 get 请求使用误区 多个参数传值为null(转载)
首先看一下官方文档是怎么描述的,传递多个值的情况(注意例子中用到的@pathParam,一般要用@queryParam) RestTemplate 实例 @Configuration public c ...
- RestTemplate 发送 get 请求使用误区 多值为null
http://blog.csdn.net/zhousenshan/article/details/71055687 ****************************************** ...
- 使用restTemplate发送post请求,传入参数是在requestBody请求体中,以json形式传输
@PostMapping public ResponseResult add(User user){ HttpHeaders httpHeaders = new HttpHeaders(); Medi ...
- RestTemplate发送GET请求
import org.springframework.web.client.RestTemplate; @Component @Slf4j public class JsSdkUtil { /** * ...
- RestTemplate发送请求并携带header信息
1.使用restTemplate的postForObject方法 注:目前没有发现发送携带header信息的getForObject方法. HttpHeaders headers = new Http ...
- 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 的结果再返 ...
随机推荐
- characteristics of competent communicators
https://www.universalclass.com/articles/business/communication-studies/be-a-competent-communicator.h ...
- find查找特殊权限用法
find查找特殊权限的用法 find選項與參數: 3. 與檔案權限及名稱有關的參數: -name filename:搜尋檔案名稱為 filename 的檔案: -size [+-]SIZE:搜尋比 S ...
- mysql5.7多实例安装
[root@vhost1]# cd /opt/source[root@vhost1]#ls mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz[root@vhost1 ...
- 爱好-超级IP:超级IP
ylbtech-爱好-超级IP:超级IP IP,是Intellectual Property的缩写,字面粗译为“知识产权”,特指具有长期生命力和商业价值的跨媒介内容运营.一个具有可开发价值的真正的I ...
- 测开之路九十五:css进阶之光标和溢出内容处理
光标样式:cursor 准备文字 css 溢出内容处理:overflow,默认溢出部分是显示 先把内容放到盒子里面 正常显示 不显示溢出内容 显示为滚动条 自动处理 css /* 光标样式 */p{ ...
- 发邮件--yagmail模块
准备工作:1.在你的邮箱设置里面打开smtp服务(若有的话)2.开启邮箱授权码,记住这个授权码(连接邮箱服务时用) 1.安装yagmail模块pip install yagmail2.举例:impor ...
- .net任务调度平台 Dyd.BaseService.TaskManager
国外网速慢,最新版本迁移至http://git.oschina.net/chejiangyi/Dyd.BaseService.TaskManager .net 简单任务调度平台 用于.net dll, ...
- Implement Queue using Stacks(用两个栈实现队列)
来源:https://leetcode.com/problems/implement-queue-using-stacks Implement the following operations of ...
- c语言秋季作业2
问题 答案 这个作业属于哪个课程 C语言程序设计I 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/8657 我在这 ...
- css定位:相对定位、绝对定位、固定定位的区别与特性
css定位:相对定位.绝对定位.固定定位的区别与特性 原文地址:http://www.qingzhouquanzi.com/106.html css定位常用的有以下三种: 使用了定位的共同特性: 这三 ...